Skip to content

Instantly share code, notes, and snippets.

@erbriones
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erbriones/29a4d0bf0e711c8ef384 to your computer and use it in GitHub Desktop.
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
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