319

How can I query/filter in Django and ignore the cases of my query-string?

I've got something like and like to ignore the case of my_parameter:

MyClass.objects.filter(name=my_parameter)

1 Answer 1

600

I solved it like this:

MyClass.objects.filter(name__iexact=my_parameter)

There is even a way to use it for substring search:

MyClass.objects.filter(name__icontains=my_parameter)

There's a link to the documentation.

Sign up to request clarification or add additional context in comments.

7 Comments

Would you please explain what "substring search" means?
@RishabhAgrahari You search inside a string, for example you search for "beer" and you get the matches "beer" and "beers".
And for example a match with "there is beer in my stomach".
Well done sir, this has given me like 3 hours of trouble :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.