From b7bcaeff63149afc88aab7e73871fafc263119f2 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 2 Jun 2023 17:35:20 +0100 Subject: [PATCH] Use `alias` instead of annotate for intermediary similarity values --- website/blog/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/blog/models.py b/website/blog/models.py index 049faab..1d38e28 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -74,7 +74,7 @@ class BlogPostPage(BaseContentPage): except BlogPostListPage.DoesNotExist: return BlogPostPage.objects.none() - similar_posts = listing_pages.exclude(id=self.id).annotate( + similar_posts = listing_pages.exclude(id=self.id).alias( title_similarity=TrigramSimilarity("title", self.title), # If this page has no subtitle, ignore it as part of similarity subtitle_similarity=TrigramSimilarity("subtitle", self.subtitle) @@ -83,7 +83,7 @@ class BlogPostPage(BaseContentPage): ) page_tags = list(self.tags.values_list("id", flat=True)) - similar_posts = similar_posts.annotate( + similar_posts = similar_posts.alias( # If this page has no tags, ignore it as part of similarity # NB: Cast to a float, because `COUNT` returns a `bigint`. tag_similarity=Cast(