Last active
August 29, 2015 14:22
-
-
Save erbriones/29a4d0bf0e711c8ef384 to your computer and use it in GitHub Desktop.
Django create query to match a collection of names in a case insensitive way
This file contains 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
import operator | |
from django.db import models | |
def name_matches(names, model): | |
queries = [models.Q(name__iequal=name for name in names)] | |
filters = reduce(operator.or_, queries, models.Q()) | |
return model.objects.filter(filters) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment