django-admin2/example2/polls/models.py

28 lines
770 B
Python
Raw Normal View History

2013-06-05 02:06:33 +00:00
import datetime
2013-06-05 01:10:59 +00:00
from django.db import models
2013-06-05 02:06:33 +00:00
from django.utils import timezone
2013-06-05 01:10:59 +00:00
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
2013-06-05 01:59:15 +00:00
was_published_recently.admin_order_field = 'pub_date'
was_published_recently.boolean = True
was_published_recently.short_description = 'Published recently?'
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __unicode__(self):
return self.choice_text