Exclude self from related articles

This commit is contained in:
Gabriel Augendre 2021-12-27 11:21:47 +01:00
parent ecc2e301b7
commit c1515c6cf7

View file

@ -132,7 +132,9 @@ class Article(models.Model):
@cached_property @cached_property
def get_related_articles(self): def get_related_articles(self):
related_articles = set() 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( for tag in self.tags.all().prefetch_related(
Prefetch("articles", published_articles, to_attr="published_articles") Prefetch("articles", published_articles, to_attr="published_articles")
): ):