Django Philosophy and Queries

19 views
Skip to first unread message

Yves de Champlain

unread,
Jun 11, 2020, 10:28:22 AM6/11/20
to Django users
Hi

I am wondering at some ways one can write a query in Django. Let's say for example :

Whatever.objects.filter(fk_object_id=fk_object_id)
Whatever.objects.filter(fk_object_id=fk_object.id)
Whatever.objects.filter(fk_object=fk_object)

and I could add to that list fk_object__id and fk_object__id__exact but my question is that while these syntaxes are equivalent in termes of results, one of them has got to be more efficient. I have read some posts about the subject, usually about optimizations, and could also guess that using an ID directly makes less behind-the-scene operations. On the other side, fk_object=fk_object surely looks more clean and concise to me.

I know I don't master the subtleties of all these syntaxes, but my question is why does Django not support only one (the most) efficient way of writing queries ?

Thanks for your thoughts about this.

Integr@te System

unread,
Jun 11, 2020, 11:23:01 AM6/11/20
to django...@googlegroups.com
Hi Yves,

zen!
Nice.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/15077d25-1460-4783-9339-7e0ce8d21259o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages