Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jonathan Buchanan authored March 14, 2007

Showing 1 changed file with 8 additions and 5 deletions. Show diff stats Hide diff stats

  1. 13  models.py
13  models.py
@@ -5,12 +5,14 @@
5 5
 class VoteManager(models.Manager):
6 6
     def get_score(self, obj):
7 7
         """
8  
-        Get the total score for ``obj`` and the number of votes it's received.
  8
+        Get a dictionary containing the total score for ``obj`` and
  9
+        the number of votes it's received.
9 10
         """
10 11
         query = """
11  
-SELECT SUM(vote), COUNT(*) FROM %s
  12
+SELECT SUM(vote), COUNT(*)
  13
+FROM %s
12 14
 WHERE content_type_id = %%s
13  
-  AND object_id = %%s""" % self.model._meta.db_table
  15
+  AND object_id = %%s""" % backend.quote_name(self.model._meta.db_table)
14 16
         ctype = ContentType.objects.get_for_model(obj)
15 17
         cursor = connection.cursor()
16 18
         cursor.execute(query, [ctype.id, obj.id])
@@ -70,9 +72,10 @@ def get_top(self, Model, limit=10, reversed=False):
70 72
         """
71 73
         ctype = ContentType.objects.get_for_model(Model)
72 74
         query = """
73  
-SELECT object_id, SUM(vote) AS score FROM %s
  75
+SELECT object_id, SUM(vote)
  76
+FROM %s
74 77
 WHERE content_type_id = %%s
75  
-GROUP BY object_id""" % self.model._meta.db_table
  78
+GROUP BY object_id""" % backend.quote_name(self.model._meta.db_table)
76 79
         if reversed:
77 80
             query += 'HAVING SUM(vote) < 0 ORDER BY SUM(vote) ASC LIMIT %s'
78 81
         else:

0 notes on commit 1e100f4

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