From c1515c6cf7827fac3051a48658cdfc004010d9bb Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 27 Dec 2021 11:21:47 +0100 Subject: [PATCH] Exclude self from related articles --- src/articles/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/articles/models.py b/src/articles/models.py index 592d664..a5b9aa0 100644 --- a/src/articles/models.py +++ b/src/articles/models.py @@ -132,7 +132,9 @@ class Article(models.Model): @cached_property def get_related_articles(self): related_articles = set() - published_articles = Article.objects.filter(status=Article.PUBLISHED) + published_articles = Article.objects.filter(status=Article.PUBLISHED).exclude( + pk=self.pk + ) for tag in self.tags.all().prefetch_related( Prefetch("articles", published_articles, to_attr="published_articles") ):