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
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")
):