Skip to content

Commit

Permalink
Ignorer les accents dans les recherches dans Django admin (#1108)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienheureux authored Dec 5, 2024
1 parent c219fc4 commit f78617d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions core/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib.postgres.lookups import Unaccent
from django.db.models import CharField, TextField

# Useful to support unaccent lookups in django admin, for
# acteurs and produits for example
CharField.register_lookup(Unaccent)
TextField.register_lookup(Unaccent)
4 changes: 2 additions & 2 deletions qfdmd/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SuggestionAdmin(admin.ModelAdmin):
@admin.register(Produit)
class ProduitAdmin(admin.ModelAdmin):
list_display = ("nom", "id", "synonymes_existants")
search_fields = ["nom", "id", "synonymes_existants"]
search_fields = ["nom__unaccent", "id", "synonymes_existants__unaccent"]
# ajout des filtres de recherche sur bdd et code
list_filter = ["bdd", "code"]
inlines = [SynonymeInline, LienInline]
Expand All @@ -49,5 +49,5 @@ class LienAdmin(NotEditableInlineMixin, admin.ModelAdmin):
@admin.register(Synonyme)
class SynonymeAdmin(NotEditableInlineMixin, ImportExportModelAdmin, admin.ModelAdmin):
resource_classes = [SynonymeResource]
search_fields = ["nom"]
search_fields = ["nom__unaccent"]
list_display = ("nom", "produit", "slug")
2 changes: 1 addition & 1 deletion qfdmo/admin/acteur.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class BaseActeurAdmin(admin.GISModelAdmin):
search_fields = [
"code_postal",
"identifiant_unique",
"nom",
"nom__unaccent",
"siret",
"ville",
]
Expand Down

0 comments on commit f78617d

Please sign in to comment.