Ignoring things with __startswith

I am trying to filter out an object based on its first letter with:

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

The problem is that the name can be β€œexample” or β€œexample”, and I want to get the whole special category regardless of the case.

How to do it?

+7
django
source share
1 answer

Do you want __istartswith :

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

There are many additions to the versions of query filters i that are case insensitive: icontains, iexact, iregex, etc.

+18
source share

All Articles