Reputation: 1717
My site has a bunch of Thread objects
>>> Thread.objects.filter(board__name='Fitness')
[<Thread: lorem>, <Thread: lorems>, <Thread: LOREM>]
And each user has a list of filters, (Postgresql Array Field)
>>> filters
['lorem', 'adipisci', 'amet', 'dolor']
I want be to able to exclude threads that are in the users filter list. So far this is the only way I've been able to achieve this:
>>> Thread.objects.filter(board__name='Fitness').exclude(reduce(operator.or_, (Q(title__icontains=x) for x in filters)))
[]
I'm wondering if there's a way to do case insensitive checks in Django with the in operator. Since the below does not work
>>> Thread.objects.filter(board__name='Fitness').exclude(title__in=filters)
[<Thread: lorems>, <Thread: LOREM>]
Preferably from within Django, and not having to mess with the Database itself
Upvotes: 1
Views: 589