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
|
@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")
|
||||||
):
|
):
|
||||||
|
|
Reference in a new issue