From d1b3113c5695b160da8cec0e8b9fba7e9cec2b8a Mon Sep 17 00:00:00 2001
From: Ondrej Rehounek <ondra.rehounek@seznam.cz>
Date: Sun, 20 Feb 2022 18:42:07 +0100
Subject: [PATCH] district and region: Set ordering as '-last_published_at'

---
 district/models.py | 14 ++++++++++----
 region/models.py   | 14 ++++++++++----
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/district/models.py b/district/models.py
index adc4abe4..3b5c0017 100644
--- a/district/models.py
+++ b/district/models.py
@@ -193,7 +193,13 @@ class DistrictHomePage(MetadataPageMixin, CalendarMixin, Page):
 
     @property
     def articles(self):
-        return self.get_descendants().type(DistrictArticlePage).live().specific()[:6]
+        return (
+            self.get_descendants()
+            .type(DistrictArticlePage)
+            .live()
+            .specific()
+            .order_by("-last_published_at")[:6]
+        )
 
     @property
     def articles_page(self):
@@ -271,7 +277,7 @@ class DistrictArticlePage(ArticleMixin, SubpageMixin, MetadataPageMixin, Page):
             self.get_siblings(inclusive=False)
             .live()  # TODO? filtrovat na stejné tagy?
             .specific()
-            .order_by("-uniwebarticlepage__date")[:3]
+            .order_by("-last_published_at")[:3]
         )
         return context
 
@@ -302,7 +308,7 @@ class DistrictArticlesPage(SubpageMixin, MetadataPageMixin, Page):
     def get_context(self, request):
         context = super().get_context(request)
         context["articles"] = Paginator(
-            self.get_children().live().specific(),
+            self.get_children().live().specific().order_by("-last_published_at"),
             self.max_items,
         ).get_page(request.GET.get("page"))
         return context
@@ -388,7 +394,7 @@ class DistrictTagsPage(SubpageMixin, MetadataPageMixin, Page):
 
         return {
             "article_page_list": Paginator(
-                article_page_qs,
+                article_page_qs.order_by("-last_published_at"),
                 self.root_page.articles_page.max_items,
             ).get_page(request.GET.get("page")),
             "tag": tag,
diff --git a/region/models.py b/region/models.py
index fcd921ba..2c88828d 100644
--- a/region/models.py
+++ b/region/models.py
@@ -193,7 +193,13 @@ class RegionHomePage(MetadataPageMixin, CalendarMixin, Page):
 
     @property
     def articles(self):
-        return self.get_descendants().type(RegionArticlePage).live().specific()[:6]
+        return (
+            self.get_descendants()
+            .type(RegionArticlePage)
+            .live()
+            .specific()
+            .order_by("-last_published_at")[:6]
+        )
 
     @property
     def articles_page(self):
@@ -269,7 +275,7 @@ class RegionArticlePage(ArticleMixin, SubpageMixin, MetadataPageMixin, Page):
             self.get_siblings(inclusive=False)
             .live()
             .specific()
-            .order_by("-uniwebarticlepage__date")[:3]
+            .order_by("-last_published_at")[:3]
         )
         return context
 
@@ -300,7 +306,7 @@ class RegionArticlesPage(SubpageMixin, MetadataPageMixin, Page):
     def get_context(self, request):
         context = super().get_context(request)
         context["articles"] = Paginator(
-            self.get_children().live().specific(),
+            self.get_children().live().specific().order_by("-last_published_at"),
             self.max_items,
         ).get_page(request.GET.get("page"))
         return context
@@ -386,7 +392,7 @@ class RegionTagsPage(SubpageMixin, MetadataPageMixin, Page):
 
         return {
             "article_page_list": Paginator(
-                article_page_qs,
+                article_page_qs.order_by("-last_published_at"),
                 self.root_page.articles_page.max_items,
             ).get_page(request.GET.get("page")),
             "tag": tag,
-- 
GitLab