Display only published articles in related
This commit is contained in:
parent
d66a2168a5
commit
4443350b3a
1 changed files with 1 additions and 1 deletions
|
@ -132,7 +132,7 @@ class Article(models.Model):
|
||||||
def get_related_articles(self):
|
def get_related_articles(self):
|
||||||
related_articles = set()
|
related_articles = set()
|
||||||
for tag in self.tags.all():
|
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])
|
sample_size = min([len(related_articles), 3])
|
||||||
return random.sample(related_articles, sample_size)
|
return random.sample(related_articles, sample_size)
|
||||||
|
|
||||||
|
|
Reference in a new issue