Use "contains" and "iexact" at the same query in DJANGO

rayashi picture rayashi · Apr 5, 2012 · Viewed 34.8k times · Source

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')

Answer

agf picture agf · Apr 5, 2012

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.