Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reformatted queries and updated get_score docstring

git-svn-id: https://django-voting.googlecode.com/svn/trunk@36 662f01ad-f42a-0410-a340-718c64ddaef4
  • Loading branch information...
commit 1e100f475fe87db6939ddbee66b4469cde406e6e 1 parent 6e2e9aa
@insin insin authored
Showing with 8 additions and 5 deletions.
  1. +8 −5 models.py
View
13 models.py
@@ -5,12 +5,14 @@
class VoteManager(models.Manager):
def get_score(self, obj):
"""
- Get the total score for ``obj`` and the number of votes it's received.
+ Get a dictionary containing the total score for ``obj`` and
+ the number of votes it's received.
"""
query = """
-SELECT SUM(vote), COUNT(*) FROM %s
+SELECT SUM(vote), COUNT(*)
+FROM %s
WHERE content_type_id = %%s
- AND object_id = %%s""" % self.model._meta.db_table
+ AND object_id = %%s""" % backend.quote_name(self.model._meta.db_table)
ctype = ContentType.objects.get_for_model(obj)
cursor = connection.cursor()
cursor.execute(query, [ctype.id, obj.id])
@@ -70,9 +72,10 @@ def get_top(self, Model, limit=10, reversed=False):
"""
ctype = ContentType.objects.get_for_model(Model)
query = """
-SELECT object_id, SUM(vote) AS score FROM %s
+SELECT object_id, SUM(vote)
+FROM %s
WHERE content_type_id = %%s
-GROUP BY object_id""" % self.model._meta.db_table
+GROUP BY object_id""" % backend.quote_name(self.model._meta.db_table)
if reversed:
query += 'HAVING SUM(vote) < 0 ORDER BY SUM(vote) ASC LIMIT %s'
else:

0 comments on commit 1e100f4

Please sign in to comment.
Something went wrong with that request. Please try again.