2👍
✅
You could easily do something like this:
sites_list = Site.objects.filter(worker=worker)
for site in sites_list:
new_sites_list = Site.objects.filter(name=site.name).filter(something else)
0👍
You can also use the __in
lookup type. For example, if you had an Entry
model with a relation to Site
, you could write:
Entry.objects.filter(site__in=Site.objects.filter(...some conditions...))
This will end up doing one query in the DB (the filter condition on sites would be turned into a subquery in the WHERE
clause).
- [Answered ]-Django MEDIA_ROOT
- [Answered ]-Rename reference to Django messages in templates?
- [Answered ]-Why are there one model.py per app instead of just one model.py out through the whole project?
Source:stackexchange.com