Reputation: 553
Suppose I have two users with username 'AbA' and 'aBa' in the database. My query word is 'ab'.
I used
User.objects.filter(username__contains='ab')
and
User.objects.filter(username__iexact='ab')
These two queries get empty result. However, I want to use something like username__contains__iexact='ab'
that can retrieve both 'AbA' and 'aBa'.
Anyone know how to resolve this problem? Thanks.
Upvotes: 40
Views: 15805
Reputation: 25936
icontains
is case-insensitive - http://docs.djangoproject.com/en/dev/ref/models/querysets/#std:fieldlookup-icontains
Upvotes: 14