1👍
✅
If Model
isnt 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 yourself obj
:
“will automatically “follow” foreign-key relationships, selecting that
additional related-object data when it executes its query”
my_objects = Model.objects.select_related().filter(user = request.user)
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
👤levi
Source:stackexchange.com