Skip to content

Instantly share code, notes, and snippets.

@rvause
Created March 13, 2014 19:26
Show Gist options
  • Select an option

  • Save rvause/9535146 to your computer and use it in GitHub Desktop.

Select an option

Save rvause/9535146 to your computer and use it in GitHub Desktop.
Compile a complex query in Django
from operator import or_
from django.db.models import Q
from .models import MyModel
query = reduce(or_, [Q(some_field__iexact=v, other_field__icontains=v) for v in values])
MyModel.objects.filter(query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment