Skip to content

Commit

Permalink
feat(admin): filtrage des stats de forum, ajout tri (#701)
Browse files Browse the repository at this point in the history
## Description

🎸 suite #699

## Type de changement

🚧 technique

### Points d'attention

🦺 amélioration `lookups`
  • Loading branch information
vincentporte authored Jul 1, 2024
1 parent f7f26b8 commit 1da74df
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lacommunaute/stats/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)}"
Expand Down

0 comments on commit 1da74df

Please sign in to comment.