开发者

Ignoring case with __startswith

开发者 https://www.devze.com 2022-12-16 22:48 出处:网络
I\'m trying to filter an object based开发者_运维百科 off its first letter with: topics = SpecialtyCategory.objects.filter(name__startswith=request.GET.get(\'filter\'))

I'm trying to filter an object based开发者_运维百科 off its first letter with:

topics = SpecialtyCategory.objects.filter(name__startswith=request.GET.get('filter'))

The problem is that the name could be "Example" or "example" and I want to get all SpecialtyCategory regardless of the case.

How do I do this?


You want __istartswith:

topics = SpecialtyCategory.objects.filter(name__istartswith=request.GET.get('filter'))

There is a whole complement of i versions of queryset filters, which are all case insensitive: icontains, iexact, iregex, etc.

0

精彩评论

暂无评论...
验证码 换一张
取 消