Un fichier de migration doit être créé et appliqué manuellement.
Commencez par créer une migration vide :
./manage.py makemigrations myapp --empty
Ouvrez ensuite le fichier et ajoutez UnaccentExtension aux operations :
from django.contrib.postgres.operations import UnaccentExtension
class Migration(migrations.Migration):
dependencies = [
(<snip>)
]
operations = [
UnaccentExtension()
]
Appliquez maintenant la migration en utilisant ./manage.py migrate .
Si vous obtenez l'erreur suivante lors de cette dernière étape :
django.db.utils.ProgrammingError: permission denied to create extension "unaccent"
HINT: Must be superuser to create this extension.
... puis accordez temporairement les droits de superutilisateur à votre utilisateur en exécutant postgres# ALTER ROLE <user_name> SUPERUSER; et son NOSUPERUSER homologue. pgAdminIII peut également le faire.
Profitez maintenant de la fonctionnalité sans accent avec Django :
>>> Person.objects.filter(first_name__unaccent=u"Helène")
[<Person: Michels Hélène>]