300

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)
ivanleoncz
  • 9,070
  • 7
  • 57
  • 49
Ron
  • 22,128
  • 31
  • 108
  • 206

1 Answers1

564

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.

Ron
  • 22,128
  • 31
  • 108
  • 206