How can I use contains
and iexact
Field lookups at the same query in Django?
Like that ..
casas = Casa.objects.filter(nome_fantasia__contains__iexact='green')
Retrieving objects. To retrieve objects from your database, construct a QuerySet via a Manager on your model class. A QuerySet represents a collection of objects from your database. It can have zero, one or many filters.
Definition and Usage The contains lookup is used to get records that contains a specified value. The contains lookup is case sensitive. For a case insensitive search, use the icontains lookup.
To do a not equal in Python Django queryset filtering, we can negate a equal with ~ . to call filter with the Q object negated with ~ to return all the Entry results that don't have id 3.
If you need case-insensitive contains
, use icontains
:
casas = Casa.objects.filter(nome_fantasia__icontains = 'green')
Which is converted to
... WHERE nome_fantasia ILIKE '%green%'
in SQL.
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