diff --git a/ratings/models.py b/ratings/models.py index 7d95d5c..87bfcb4 100644 --- a/ratings/models.py +++ b/ratings/models.py @@ -207,6 +207,10 @@ def unrate(self, user): def perform_aggregation(self, aggregator): score = self.all().aggregate(agg=aggregator('score')) return score['agg'] + + def count(self): + # the number of votes + return self.perform_aggregation(models.Count) def cumulative_score(self): # simply the sum of all scores, useful for +1/-1 diff --git a/ratings/views.py b/ratings/views.py index cb99cab..4707508 100644 --- a/ratings/views.py +++ b/ratings/views.py @@ -5,6 +5,7 @@ HttpResponseNotAllowed, Http404 from django.shortcuts import get_object_or_404 +import json # allow GET requests to create ratings -- this goes against the "GET" requests # should be idempotent but avoids the necessity of using