From 04736aa4059f1e2c14d6770b0f4f3ce02c36200b Mon Sep 17 00:00:00 2001 From: Fred Pauchet Date: Tue, 10 Jan 2023 21:48:33 +0100 Subject: [PATCH] Try to sort articles, based on their published_dates --- jack/models.py | 20 ++++++++++++++++++-- templates/index.html | 2 +- templates/section.html | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/jack/models.py b/jack/models.py index e6f079e..dfee28f 100644 --- a/jack/models.py +++ b/jack/models.py @@ -72,11 +72,27 @@ class Article: class PublishedUnpublished: @property def published_articles(self): - return [x for x in self.articles if x.published_date] + results = [x for x in self.articles if x.published_date] + + sorted( + results, + key=lambda x: x.pubished_date, + reverse=True, + ) + + return results @property def articles_without_date(self): - return [x for x in self.articles if not x.published_date] + results = [x for x in self.articles if not x.published_date] + + sorted( + results, + key=lambda x: x.pubished_date, + reverse=True, + ) + + return results class Section(PublishedUnpublished): diff --git a/templates/index.html b/templates/index.html index 30987f2..8d534a4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,7 +7,7 @@