PostgreSQL specific lookups¶
trigram_similar lookup allows you to perform trigram lookups,
measuring the number of trigrams (three consecutive characters) shared, using a
dedicated PostgreSQL extension. A trigram lookup is given an expression and
returns results that have a similarity measurement greater than the current
>>> City.objects.filter(name__trigram_similar="Middlesborough") ['<City: Middlesbrough>']
unaccent lookup allows you to perform accent-insensitive lookups using
a dedicated PostgreSQL extension.
This lookup is implemented using
Transform, so it
can be chained with other lookup functions. To use it, you need to add
'django.contrib.postgres' in your
INSTALLED_APPS and activate
the unaccent extension on PostgreSQL. The
operation is available if you want to perform this activation using migrations).
>>> City.objects.filter(name__unaccent="México") ['<City: Mexico>'] >>> User.objects.filter(first_name__unaccent__startswith="Jerem") ['<User: Jeremy>', '<User: Jérémy>', '<User: Jérémie>', '<User: Jeremie>']
unaccent lookups should perform fine in most use cases. However, queries
using this filter will generally perform full table scans, which can be slow
on large tables. In those cases, using dedicated full text indexing tools
might be appropriate.