1 | from django.db import models
|
---|
2 | import datetime
|
---|
3 | from django.utils import timezone
|
---|
4 |
|
---|
5 | # Create your models here.
|
---|
6 |
|
---|
7 | class 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 |
|
---|
21 | class 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
|
---|