From f567b1a34339af8cc019ed4885508f8fae73f856 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 29 May 2020 21:37:44 +0200 Subject: [PATCH] Activity list is displayed in the right order --- apps/activity/views.py | 8 ++++---- apps/permission/views.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/activity/views.py b/apps/activity/views.py index ef144460..df3f00ea 100644 --- a/apps/activity/views.py +++ b/apps/activity/views.py @@ -36,9 +36,7 @@ class ActivityCreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): class ActivityListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): model = Activity table_class = ActivityTable - - def get_queryset(self): - return super().get_queryset().reverse() + ordering = ('-date_start',) def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -47,7 +45,9 @@ class ActivityListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView upcoming_activities = Activity.objects.filter(date_end__gt=datetime.now()) context['upcoming'] = ActivityTable( - data=upcoming_activities.filter(PermissionBackend.filter_queryset(self.request.user, Activity, "view"))) + data=upcoming_activities.filter(PermissionBackend.filter_queryset(self.request.user, Activity, "view")), + prefix='upcoming-', + ) return context diff --git a/apps/permission/views.py b/apps/permission/views.py index cbd26a19..ab555c2f 100644 --- a/apps/permission/views.py +++ b/apps/permission/views.py @@ -19,7 +19,7 @@ class ProtectQuerysetMixin: """ def get_queryset(self, **kwargs): qs = super().get_queryset(**kwargs) - return qs.filter(PermissionBackend.filter_queryset(self.request.user, qs.model, "view")) + return qs.filter(PermissionBackend.filter_queryset(self.request.user, qs.model, "view")).distinct() def get_form(self, form_class=None): form = super().get_form(form_class)