diff --git a/apps/rp/models/vote.py b/apps/rp/models/vote.py index b91576bb8c0c9a15fb3b256edcc1f935e2a573db..6fe502dd94e6a1204274db30361930d17207f87e 100644 --- a/apps/rp/models/vote.py +++ b/apps/rp/models/vote.py @@ -39,6 +39,8 @@ class UnDVotedMixin(models.Model): und_votes = GenericRelation(UnDVotes) #: Score of the model und_score = models.IntegerField(default=0) + und_score_up = models.IntegerField(default=0) + und_score_down = models.IntegerField(default=0) class Meta: abstract = True @@ -63,6 +65,7 @@ class UnDVotedMixin(models.Model): diff_score = 1 self.und_score += diff_score + self.und_score_up += diff_score # Update self score, use update and filter to avoid triggering signals self.__class__.objects.filter(id=self.id).update( und_score=F("und_score") + diff_score) @@ -87,13 +90,19 @@ class UnDVotedMixin(models.Model): diff_score = -1 self.und_score += diff_score + self.und_score_down += diff_score # Update self score, use update and filter to avoid triggering signals self.__class__.objects.filter(id=self.id).update( und_score=F("und_score") + diff_score) def update_und_score(self): """Reset score to the correct count (should not be necessary)""" - score = self.und_votes.aggregate(Sum("score"))["score__sum"] or 0 + score_up = self.und_votes.filter(score=1).count() + score_down = self.und_votes.filter(score=-1).count() + score = score_up + score_down + + self.und_score_up = score_up + self.und_score_down = score_down self.und_score = score # Update self score, use update and filter to avoid triggering signals self.__class__.objects.filter(id=self.id).update(und_score=score) diff --git a/apps/rp/templates/rp/article_list.html b/apps/rp/templates/rp/article_list.html index 2d688f558e2ddf91d2ef2aed2799dc1c51f6f5bc..1f730ce244c8355f5d955363f8dfef0678c11abc 100644 --- a/apps/rp/templates/rp/article_list.html +++ b/apps/rp/templates/rp/article_list.html @@ -61,8 +61,8 @@ {{article.title}} {{article.und_votes.first.username}}