Django Model - Case-insensitive Query / Filtering

DatabaseDjangoDjango ModelsFiltering

Database Problem Overview


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)

Database Solutions


Solution 1 - Database

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRonView Question on Stackoverflow
Solution 1 - DatabaseRonView Answer on Stackoverflow