diff --git a/boards/models/tag.py b/boards/models/tag.py --- a/boards/models/tag.py +++ b/boards/models/tag.py @@ -1,4 +1,4 @@ -from boards.models import Thread +from boards.models import Thread, Post from django.db import models from django.db.models import Count @@ -47,17 +47,14 @@ class Tag(models.Model): return self.threads.count() def get_popularity(self): - popularity = 0.0 + all_post_count = Post.objects.all().count() + + tag_reply_count = 0.0 for thread in self.threads.all(): - reply_count = thread.get_reply_count() + tag_reply_count += thread.get_reply_count() - thread_popularity = 0.0 - thread_popularity += REPLY_POPULARITY * reply_count - thread_popularity += OPENING_POST_POPULARITY - if thread.archived: - thread_popularity *= ARCHIVE_POPULARITY_MODIFIER - popularity += thread_popularity + popularity = tag_reply_count / all_post_count return popularity