From ee6dd9de872c66c5c4f4959cbdc04f5cc6ea9ad8 Mon Sep 17 00:00:00 2001 From: Daniel Miranda Date: Fri, 15 Nov 2024 11:17:16 -0800 Subject: [PATCH] updated query to grab featured blog pages in the correct order (#13122) * updated query to grab featured blog pages in the correct order * updated test to account for extra queries --- network-api/networkapi/nav/models.py | 2 +- network-api/networkapi/nav/tests/test_models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/network-api/networkapi/nav/models.py b/network-api/networkapi/nav/models.py index 2d39c7d8c43..c40be59a381 100644 --- a/network-api/networkapi/nav/models.py +++ b/network-api/networkapi/nav/models.py @@ -190,7 +190,7 @@ def localized_featured_blog_topics(self): def localized_featured_blog_posts(self): default_locale = settings.LANGUAGE_CODE posts = BlogPage.objects.filter( - featured_pages_relationship__isnull=False, locale__language_code=default_locale + featured_pages_relationship__page=self.blog_index_page, locale__language_code=default_locale ).order_by("featured_pages_relationship__sort_order") posts = localize_queryset(posts, preserve_order=True).prefetch_related("topics") return posts[:3] diff --git a/network-api/networkapi/nav/tests/test_models.py b/network-api/networkapi/nav/tests/test_models.py index f6fd61a9915..f1318a5f261 100644 --- a/network-api/networkapi/nav/tests/test_models.py +++ b/network-api/networkapi/nav/tests/test_models.py @@ -286,7 +286,7 @@ def setUp(self): def test_localized_featured_posts(self) -> None: # Get the localised posts: - with self.assertNumQueries(4): + with self.assertNumQueries(6): posts = self.menu.localized_featured_blog_posts self.assertEqual(len(posts), 3)