Skip to content

Instantly share code, notes, and snippets.

@sobelk
Created February 23, 2016 00:27
Show Gist options
  • Save sobelk/b8b0d29f4e051fafda86 to your computer and use it in GitHub Desktop.
Save sobelk/b8b0d29f4e051fafda86 to your computer and use it in GitHub Desktop.
from django.db.models import Q
def composite_in(columns, tuples):
return reduce(Q.__or__, [Q(**dict(zip(columns, t))) for t in tuples])
#
# MyModel.objects.filter(composite_in(
# ('col1', 'col2'),
# [(1,2), (1,3), (2,3)]))
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment