publications filtering

This commit is contained in:
bkfox 2022-08-16 14:19:34 +02:00
parent 836d3a75bf
commit 8a4d43cfb2

View File

@ -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)