From 191c51f6b43d3a3a58349e80be98ad15b4868abb Mon Sep 17 00:00:00 2001 From: edegeyer Date: Mon, 3 Aug 2020 09:40:57 +0200 Subject: [PATCH] Issue 71: separated count votes functions --- vote/managers.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/vote/managers.py b/vote/managers.py index b843ee2..a79745e 100644 --- a/vote/managers.py +++ b/vote/managers.py @@ -154,9 +154,20 @@ def all(self, user_id, action=UP): return self.model.objects.filter(pk__in=list(object_ids)) - def count(self, action=UP): + def count_up(self): return self.through.votes_for(self.model, - self.instance, action).count() + self.instance, UP).count() + + def count_down(self): + return self.through.votes_for(self.model, + self.instance, DOWN).count() + + def count(self): + votes = { + "up": self.count_up(), + "down": self.count_down() + } + return votes def user_ids(self, action=UP): return self.through.votes_for(