From 18700808b50dcfd60941e2513c3fd862dc6eab62 Mon Sep 17 00:00:00 2001
From: OndraRehounek <ondra.rehounek@seznam.cz>
Date: Fri, 4 Mar 2022 15:12:23 +0100
Subject: [PATCH] Fix ordering fields

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

diff --git a/district/models.py b/district/models.py
index dc1e8aaa..2adb5672 100644
--- a/district/models.py
+++ b/district/models.py
@@ -193,7 +193,7 @@ class DistrictHomePage(MetadataPageMixin, CalendarMixin, Page):
             .type(DistrictArticlePage)
             .live()
             .specific()
-            .order_by("-last_published_at")[:6]
+            .order_by("-districtarticlepage__date")[:6]
         )
 
     @property
@@ -276,7 +276,7 @@ class DistrictArticlePage(ArticleMixin, SubpageMixin, MetadataPageMixin, Page):
             self.get_siblings(inclusive=False)
             .live()  # TODO? filtrovat na stejné tagy?
             .specific()
-            .order_by("-last_published_at")[:3]
+            .order_by("-districtarticlepage__date")[:3]
         )
         return context
 
@@ -307,7 +307,10 @@ class DistrictArticlesPage(SubpageMixin, MetadataPageMixin, Page):
     def get_context(self, request):
         context = super().get_context(request)
         context["articles"] = Paginator(
-            self.get_children().live().specific().order_by("-last_published_at"),
+            self.get_children()
+            .live()
+            .specific()
+            .order_by("-districtarticlepage__date"),
             self.max_items,
         ).get_page(request.GET.get("page"))
         return context
@@ -393,7 +396,7 @@ class DistrictTagsPage(SubpageMixin, MetadataPageMixin, Page):
 
         return {
             "article_page_list": Paginator(
-                article_page_qs.order_by("-last_published_at"),
+                article_page_qs.order_by("-date"),
                 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 d9f9c544..decef6fb 100644
--- a/region/models.py
+++ b/region/models.py
@@ -193,7 +193,7 @@ class RegionHomePage(MetadataPageMixin, CalendarMixin, Page):
             .type(RegionArticlePage)
             .live()
             .specific()
-            .order_by("-last_published_at")[:6]
+            .order_by("-regionarticlepage__date")[:6]
         )
 
     @property
@@ -274,7 +274,7 @@ class RegionArticlePage(ArticleMixin, SubpageMixin, MetadataPageMixin, Page):
             self.get_siblings(inclusive=False)
             .live()
             .specific()
-            .order_by("-last_published_at")[:3]
+            .order_by("-regionarticlepage__date")[:3]
         )
         return context
 
@@ -305,7 +305,7 @@ class RegionArticlesPage(SubpageMixin, MetadataPageMixin, Page):
     def get_context(self, request):
         context = super().get_context(request)
         context["articles"] = Paginator(
-            self.get_children().live().specific().order_by("-last_published_at"),
+            self.get_children().live().specific().order_by("-regionarticlepage__date"),
             self.max_items,
         ).get_page(request.GET.get("page"))
         return context
@@ -391,7 +391,7 @@ class RegionTagsPage(SubpageMixin, MetadataPageMixin, Page):
 
         return {
             "article_page_list": Paginator(
-                article_page_qs.order_by("-last_published_at"),
+                article_page_qs.order_by("-date"),
                 self.root_page.articles_page.max_items,
             ).get_page(request.GET.get("page")),
             "tag": tag,
-- 
GitLab