1
from django.db import models
4
class Poll(models.Model):
5
name = models.CharField(max_length=256)
6
pub_date = models.DateTimeField("date published", default = datetime.datetime.now)
7
closed_date = models.DateTimeField("date closed", blank=True, null=True)
10
return self.choices.all().aggregate(models.Sum("votes"))["votes__sum"]
12
def __unicode__(self):
15
class Choice(models.Model):
16
poll = models.ForeignKey(Poll, related_name="choices")
17
choice = models.CharField(max_length=256)
18
votes = models.PositiveIntegerField(default=0)
20
def __unicode__(self):
21
return u"%i:%s" % (self.votes,self.choice)