Skip to content

Instantly share code, notes, and snippets.

@mgalgs
Created January 12, 2018 02:57
Show Gist options
  • Save mgalgs/7fa53d787d30bdeff87a661d7d1188a3 to your computer and use it in GitHub Desktop.
Save mgalgs/7fa53d787d30bdeff87a661d7d1188a3 to your computer and use it in GitHub Desktop.
django QuerySet.__or__
In [27]: qs1 = User.objects.filter(pk__in=[1, 2])
In [28]: qs2 = User.objects.filter(pk__in=[2, 5])
In [29]: qs3 = qs1 | qs2
In [30]: print qs3.query
SELECT "auth_user"."id", "auth_user"."password", "auth_user"."last_login", "auth_user"."is_superuser", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."date_joined" FROM "auth_user" WHERE ("auth_user"."id" IN (1, 2) OR "auth_user"."id" IN (2, 5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment