Use PostGreSQL, which currently supports the 'unaccent' extension. This makes searching for 'año' possible when only typing 'ano'.
Best thing is, you can decide whether to use this extension for every filter by, for example using
Person.objects.filter(first_name__unaccent__icontains=search)
Switch your database to PostgreSQL and add the unaccent extension as follows:
Part of answer from @SaeX in another thread:
How can I activate the unaccent extension on an already existing model
A migration file needs to be manually made and applied.
- First, create an empty migration:
./manage.py makemigrations myapp --empty
- Then open the file and add UnaccentExtension to operations:
from django.contrib.postgres.operations import UnaccentExtension
class Migration(migrations.Migration):
dependencies = [
(<snip>)
]
operations = [
UnaccentExtension()
]
- Now apply the migration using
./manage.py migrate.
If you'd get following error during that last step:
django.db.utils.ProgrammingError: permission denied to create extension "unaccent"
HINT: Must be superuser to create this extension.
... then temporarily allow superuser rights to your user by performing postgres# ALTER ROLE <user_name> SUPERUSER; and its NOSUPERUSER counterpart. pgAdminIII can do this, too.
Now enjoy the unaccent functionality using Django:
>>> Person.objects.filter(first_name__unaccent=u"Helène")
[<Person: Michels Hélène>]
Again, part of this answer belongs to @SaeX
IMPORTANT
But for me his answer still didn't work, so don't forget to
add the line django.contrib.postgres
in INSTALLED_APPS (settings.py)