From de84301df3436812a48ff8882a70c02e5f023082 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Mon, 1 Jul 2024 19:09:09 +0200 Subject: [PATCH] feat(stats): add sorting --- lacommunaute/stats/admin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lacommunaute/stats/admin.py b/lacommunaute/stats/admin.py index 5736c2122..c802d823a 100644 --- a/lacommunaute/stats/admin.py +++ b/lacommunaute/stats/admin.py @@ -10,8 +10,8 @@ class ForumWithStatsFilter(admin.SimpleListFilter): parameter_name = "forum" def lookups(self, request, model_admin): - forums_with_stats = model_admin.model.objects.values_list("forum", flat=True).distinct() - return [(forum.pk, forum.name) for forum in Forum.objects.filter(pk__in=forums_with_stats)] + forums_with_stats = model_admin.model.objects.values_list("forum", flat=True) + return Forum.objects.filter(pk__in=forums_with_stats).values_list("pk", "name") def queryset(self, request, queryset): if self.value(): @@ -23,6 +23,7 @@ class BaseStatAdmin(admin.ModelAdmin): list_display = ("explicit_period",) list_filter = ("date", "period") + @admin.display(ordering="date") def explicit_period(self, obj): if obj.period == "month": return f"{obj.date} au {obj.date + relativedelta(months=1) - relativedelta(days=1)}"