From 8a4d43cfb28fbe8d07e9e81fc3ef42e6962af13d Mon Sep 17 00:00:00 2001 From: bkfox Date: Tue, 16 Aug 2022 14:19:34 +0200 Subject: [PATCH] publications filtering --- aircox/views/home.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/aircox/views/home.py b/aircox/views/home.py index a09cecd..c1bbb04 100644 --- a/aircox/views/home.py +++ b/aircox/views/home.py @@ -15,6 +15,7 @@ class HomeView(BaseView, ListView): attach_to_value = StaticPage.ATTACH_TO_HOME queryset = Diffusion.objects.on_air().select_related('episode') logs_count = 5 + publications_count = 5 has_filters = False def get_queryset(self): @@ -37,8 +38,19 @@ class HomeView(BaseView, ListView): return diffs def get_last_publications(self): - return Page.objects.select_subclasses().published() \ - .order_by('-pub_date') + # note: with postgres db, possible to use distinct() + qs = Page.objects.select_subclasses().published() \ + .order_by('-pub_date') + parents = set() + items = [] + for publication in qs: + parent_id = publication.parent_id + if parent_id is not None and parent_id in parents: + continue + items.append(publication) + if len(items) == self.publications_count: + break + return items def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs)