Django: does the ORM support the SQL "IN" operator?

Continuation picture Continuation · Mar 30, 2011 · Viewed 15.6k times · Source

Does the Django ORM support the SQL IN operator? Something like:

SELECT *
FROM user
WHERE id IN (1, 5, 34, 567, 229)

How do I use the Django ORM to make a query like that?

Thanks.

Answer

Yuji 'Tomita' Tomita picture Yuji 'Tomita' Tomita · Mar 30, 2011

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)