lookups.txt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. ===========================
  2. PostgreSQL specific lookups
  3. ===========================
  4. ``Unaccent``
  5. ============
  6. .. fieldlookup:: unaccent
  7. The ``unaccent`` lookup allows you to perform accent-insensitive lookups using
  8. a dedicated PostgreSQL extension.
  9. This lookup is implemented using :class:`~django.db.models.Transform`, so it
  10. can be chained with other lookup functions. To use it, you need to add
  11. ``'django.contrib.postgres'`` in your :setting:`INSTALLED_APPS` and activate
  12. the `unaccent extension on PostgreSQL`_. The
  13. :class:`~django.contrib.postgres.operations.UnaccentExtension` migration
  14. operation is available if you want to perform this activation using migrations).
  15. .. _unaccent extension on PostgreSQL: http://www.postgresql.org/docs/current/interactive/unaccent.html
  16. The ``unaccent`` lookup can be used on
  17. :class:`~django.db.models.CharField` and :class:`~django.db.models.TextField`::
  18. >>> City.objects.filter(name__unaccent="México")
  19. ['<City: Mexico>']
  20. >>> User.objects.filter(first_name__unaccent__startswith="Jerem")
  21. ['<User: Jeremy>', '<User: Jérémy>', '<User: Jérémie>', '<User: Jeremie>']
  22. .. warning::
  23. ``unaccent`` lookups should perform fine in most use cases. However, queries
  24. using this filter will generally perform full table scans, which can be slow
  25. on large tables. In those cases, using dedicated full text indexing tools
  26. might be appropriate.