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
related gist: https://gist.github.com/ctrl-alt-delete/10745911
Written by Vera Mazhuga
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#