Created
March 13, 2014 19:26
-
-
Save rvause/9535146 to your computer and use it in GitHub Desktop.
Compile a complex query in Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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