From 2ae8ec70454c08f4a593fe1039403a98d42325c6 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 16 Jul 2022 10:44:48 +0100 Subject: [PATCH] Optimise getting blog posts for a tag Because we can guarantee there's only 1 `BlogListPage`, the query becomes much simpler --- website/blog/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/website/blog/models.py b/website/blog/models.py index e42bc4c..a6ce184 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -100,8 +100,9 @@ class BlogPostTagPage(BaseContentMixin, BasePage): # type: ignore[misc] ] def get_blog_posts(self) -> PageQuerySet: - blog_list_page = self.get_parent_pages().specific().reverse()[1] - assert isinstance(blog_list_page, BlogListPage) + blog_list_page = ( + BlogListPage.objects.all().live().get() # type:ignore[attr-defined] + ) return blog_list_page.get_blog_posts().filter(tags=self).order_by("-date") def get_context(self, request: HttpRequest) -> dict: