Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): filtrage des stats de forum, ajout tri #701

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading