Skip to content

Tag: django

Sort a QuerySet by ManyToManyField in Django

I have a model like this: I want to get all Objects of my_model sorted by the number of objects in the foo field. In this Question A friendly Guy from russia says, that you should use django-annontation. I tried the following: and it works fine. Is there any reason I should go the longer way with annotations?…

How to use Django session variable in models.py

I wanna use the Django session variable on models.py file. How can I do it? I want to get the user’s Pincode/zip and have to run a query using that. I need to get Pincode from the session. Answer In your model method you don’t have access to the request so you do not have access to the session. On…

‘microsecond’ is an invalid keyword argument for replace()

I am using Django 2.0+ and am attempting to just plug in the existing password reset function into my website. If the email does not exist, it successfully submits. If it DOES exist, I get this error: ‘microsecond’ is an invalid keyword argument for replace() I never touched any of the backend cod…