63👍
✅
in
User.objects.filter(id__in=[1, 5, 34, 567, 229])
print _.query
SELECT <fields> FROM "auth_user" WHERE "auth_user"."id" IN (1, 5, 34, 567, 229)
7👍
Beside that, Django ORM also support for Sub-Query:
For example:
from django.db.models import Subquery
users = User.objects.all()
UserParent.objects.filter(user_id__in=Subquery(users.values('id')))
- [Django]-How to solve "Page not found (404)" error in Django?
- [Django]-Custom ordering in Django
- [Django]-Annotate with latest related object in Django
0👍
as Yuji indicates above <field_name>__in=[<list_of_values>] is translated to the following SQL:
WHERE <field_name> IN (<list_of_values>)
you can find the complete reference of django SQL WHERE operators under the Field lookups section of the following Django API document.
- [Django]-Django sending email
- [Django]-How to create virtual env with python3
- [Django]-Why is factory_boy superior to using the ORM directly in tests?
Source:stackexchange.com