I have a Model and I am doing a query :
my_objects = Model.objects.filter(user = request.user)
now over my_objects I am doing :
obj = my_objects.get(user = x )
I am trying to understand if my .get over my_objects will not generate another query to the database and will only work on the filter output ? or it will be generating another query.
If
Modelisnt User instance, it will hit database again, because User in that case is a related object, if you dont want hit again the database, use select_related() and filter by yourselfobj:see more info here:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related
EDIT:
I forgot mention that QuerySet in django are lazy, actually don’t hit the db until you evaluate the queryset, these are methods that force to evaluate a queryset :
methods