Last Updated: February 25, 2016
·
8.92K
· vero4ka

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