~widelands-dev/widelands-website/solitaire_html_documentation

« back to all changes in this revision

Viewing changes to wlpoll/models.py

  • Committer: Holger Rapp
  • Date: 2009-03-28 12:03:48 UTC
  • Revision ID: sirver@kallisto.local-20090328120348-id7kvvww2nxhauwd
First draft version of wlpoll, a poll application

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.db import models
 
2
import datetime
 
3
 
 
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)
 
8
 
 
9
    def total_votes(self):
 
10
        return self.choices.all().aggregate(models.Sum("votes"))["votes__sum"]
 
11
 
 
12
    def __unicode__(self):
 
13
        return self.name
 
14
 
 
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)
 
19
 
 
20
    def __unicode__(self):
 
21
        return u"%i:%s" % (self.votes,self.choice)