Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
Created April 15, 2014 16:33
Show Gist options
  • Save cansadadeserfeliz/10745911 to your computer and use it in GitHub Desktop.
Save cansadadeserfeliz/10745911 to your computer and use it in GitHub Desktop.
Django: how to make case-insensitive __in query
def get_queryset(self):
queryset = super(MyModel, self).get_queryset()
states_filter = [
item.strip()
for item in config.STATES.split(',')
]
if not states_filter:
MyModel.objects.none()
q = Q()
for state in states_filter:
q = q | Q(status__iexact=state)
queryset = queryset.filter(q)
return queryset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment