Code

Ticket #19311: models.py

File models.py, 826 bytes (added by anonymous, 20 months ago)

models.py

Line 
1from django.db import models
2import datetime
3from django.utils import timezone
4
5# Create your models here.
6
7class Poll(models.Model):
8    question = models.CharField(max_length=200)
9    pub_date = models.DateTimeField('date published')
10   
11    def __unicode__(self):
12        return self.question
13       
14    def was_published_recently(self):
15        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
16    was_published_recently.admin_order_field = "pub_date"
17    was_published_recently.boolean = True
18    was_published_recently.short_description = "Published recently?"
19   
20
21class Choice(models.Model):
22    question = models.ForeignKey(Poll)
23    choice = models.CharField(max_length=200)
24    votes = models.IntegerField()
25   
26    def __unicode__(self):
27        return self.choice