Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignoring case with __startswith

Tags:

django

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?

like image 987
silent1mezzo Avatar asked Jan 21 '10 14:01

silent1mezzo


1 Answers

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.

like image 150
jcdyer Avatar answered Oct 20 '22 06:10

jcdyer