[Fixed]-Django queryset __contains case sensitive?

52👍

Use Pizza.object.filter(topping__icontains='peperoni').

Filter with __icontains check.

👤Rohan

2👍

You would need to import and use Q object:

from django.db.models import Q 

Resulting_Queryset = MyModel.objects.filter(Q(name__istartswith='Nishank Gupta'.strip().lower()) &  Q(name__iendswith='Nishank Gupta'.strip().lower()))

This would match Nishank Gupta and Nishank GUPTA and NisHANnk Gupta and so on. Hope this helps. Please do let me know your views.

Or Use iexact:

MyModel.objects.filter(name__iexact='Nishank Gupta'.strip().lower()) 

Leave a comment