# HG changeset patch # User neko259 # Date 2015-08-12 15:41:57 # Node ID ba7bc8dbc38eb217aeb1c8f4e63a3c80e1ad5689 # Parent 819f972ff3323d07280fa16fc50ecfbffa0f5cee Add up to 5 random related tags instead of all related list diff --git a/boards/models/tag.py b/boards/models/tag.py --- a/boards/models/tag.py +++ b/boards/models/tag.py @@ -10,6 +10,9 @@ import boards __author__ = 'neko259' +RELATED_TAGS_COUNT = 5 + + class TagManager(models.Manager): def get_not_empty_tags(self): @@ -102,5 +105,5 @@ class Tag(models.Model, Viewable): return self.name and self.name[0] or '' def get_related_tags(self): - return Tag.objects.filter(thread_tags__in=self.get_threads()).exclude( - id=self.id).distinct() + return set(Tag.objects.filter(thread_tags__in=self.get_threads()).exclude( + id=self.id).order_by('?')[:RELATED_TAGS_COUNT]) diff --git a/boards/views/tag_threads.py b/boards/views/tag_threads.py --- a/boards/views/tag_threads.py +++ b/boards/views/tag_threads.py @@ -51,7 +51,7 @@ class TagView(AllThreadsView, Dispatcher params[PARAM_IS_HIDDEN] = hidden_tag_names is not None and tag.name in hidden_tag_names params[PARAM_RANDOM_IMAGE_POST] = tag.get_random_image_post() - params[PARAM_RELATED_TAGS] = tag.get_related_tags().all() + params[PARAM_RELATED_TAGS] = tag.get_related_tags() return params