Django Model - Case-insensitive Query / Filtering

后端 未结 1 1464
说谎
说谎 2020-12-04 10:52

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:

相关标签:
1条回答
  • 2020-12-04 11:04

    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.

    0 讨论(0)
提交回复
热议问题