Exclude self from related articles
This commit is contained in:
parent
ecc2e301b7
commit
c1515c6cf7
1 changed files with 3 additions and 1 deletions
|
@ -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")
|
||||
):
|
||||
|
|
Reference in a new issue