I want to perform a simple query:
Pizza.object.filter(topping__contains='PEPERONI')
Like this, it works like a charm. But if I try that:
Pizza.object.filter(topping__contains='peperoni')
It is not working.
Do you know why it is case sensitive ? Is there an option to cancel this feature from django ?
Use Pizza.object.filter(topping__icontains='peperoni')
.
Filter with __icontains
check.
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With