Display only published articles in related

This commit is contained in:
Gabriel Augendre 2021-03-20 11:17:11 +01:00
parent d66a2168a5
commit 4443350b3a

View file

@ -132,7 +132,7 @@ class Article(models.Model):
def get_related_articles(self):
related_articles = set()
for tag in self.tags.all():
related_articles.update(tag.articles.all())
related_articles.update(tag.articles.filter(status=Article.PUBLISHED))
sample_size = min([len(related_articles), 3])
return random.sample(related_articles, sample_size)