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)