Friday, March 29, 2013

Question about documentauion under Managers>Adding extra Manager methods

In the example:
class PollManager(models.Manager):      def with_counts(self):          from django.db import connection          cursor = connection.cursor()          cursor.execute("""              SELECT p.id, p.question, p.poll_date, COUNT(*)              FROM polls_opinionpoll p, polls_response r              WHERE p.id = r.poll_id              GROUP BY 1, 2, 3              ORDER BY 3 DESC""")          result_list = []          for row in cursor.fetchall():              p = self.model(id=row[0], question=row[1], poll_date=row[2])              p.num_responses = row[3]              result_list.append(p)          return result_list    class OpinionPoll(models.Model):      question = models.CharField(max_length=200)      poll_date = models.DateField()      objects = PollManager()    class Response(models.Model):      poll = models.ForeignKey(OpinionPoll)      person_name = models.CharField(max_length=50)      response = models.TextField()

What is the sql dialect that is used.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment