Skip to content

Commit

Permalink
set filter and order in queryset for sous categorie proposition service
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienheureux committed Jul 22, 2024
1 parent d8e83de commit 53543f3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions qfdmo/admin/acteur.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,21 @@ def __init__(self, *args, **kwargs):
).order_by("libelle_unaccent")
)

filter_horizontal = [
"sous_categories",
]

class InlinePropositionServiceForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if "sous_categories" in self.fields:
self.fields["sous_categories"].queryset = (
SousCategorieObjet.objects.annotate(
libelle_unaccent=Unaccent(Lower("libelle")),
categorie_libelle_unaccent=Unaccent(Lower("categorie__libelle")),
).order_by("categorie_libelle_unaccent", "libelle_unaccent")
)


class BasePropositionServiceInline(admin.TabularInline):
form = BasePropositionServiceForm
form = InlinePropositionServiceForm
extra = 0

fields = (
Expand All @@ -108,6 +116,8 @@ class BasePropositionServiceInline(admin.TabularInline):
"sous_categories",
)

filter_vertical = ("sous_categories",)


class PropositionServiceInline(BasePropositionServiceInline, NotEditableInlineMixin):
model = PropositionService
Expand Down
2 changes: 1 addition & 1 deletion qfdmo/models/categorie_objet.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Meta:
)

def __str__(self) -> str:
return self.libelle
return f"{self.categorie.libelle} | {self.libelle}"

@cached_property
def url_carte(self):
Expand Down

0 comments on commit 53543f3

Please sign in to comment.