Permalink
Browse files

Added get_for_user_in_bulk helper method

git-svn-id: https://django-voting.googlecode.com/svn/trunk@23 662f01ad-f42a-0410-a340-718c64ddaef4
  • Loading branch information...
1 parent b955f81 commit 71ea2cc4e235a065c1b0a7e4360cf965eb336cf9 @insin insin committed Mar 13, 2007
Showing with 14 additions and 0 deletions.
  1. +14 −0 models.py
View
@@ -89,6 +89,20 @@ def get_for_user(self, obj, user):
vote = None
return vote
+ def get_for_user_in_bulk(self, objects, user):
+ """
+ Get a dictionary mapping object ids to votes made by the given
+ user on the corresponding objects.
+ """
+ vote_dict = {}
+ if len(objects) > 0:
+ ctype = ContentType.objects.get_for_model(objects[0])
+ votes = list(self.filter(content_type__pk=ctype.id,
+ object_id__in=[obj.id for obj in objects],
+ user__pk=user.id))
+ vote_dict = dict([(vote.object_id, vote) for vote in votes])
+ return vote_dict
+
SCORES = (
('+1', +1),
('-1', -1),

0 comments on commit 71ea2cc

Please sign in to comment.