2013-07-07 14:13:48 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
from __future__ import division, absolute_import, unicode_literals
|
|
|
|
|
|
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
|
2016-05-07 23:31:16 +00:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2013-07-07 08:15:22 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2013-06-05 01:10:59 +00:00
|
|
|
|
2013-06-05 01:22:21 +00:00
|
|
|
|
2014-11-26 15:42:17 +00:00
|
|
|
@python_2_unicode_compatible
|
2013-06-05 01:22:21 +00:00
|
|
|
class Poll(models.Model):
|
2013-07-07 08:15:22 +00:00
|
|
|
question = models.CharField(max_length=200, verbose_name=_('question'))
|
|
|
|
|
pub_date = models.DateTimeField(verbose_name=_('date published'))
|
2013-06-05 01:22:21 +00:00
|
|
|
|
2014-11-26 15:42:17 +00:00
|
|
|
def __str__(self):
|
2013-06-05 01:22:21 +00:00
|
|
|
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
|
2013-07-07 08:15:22 +00:00
|
|
|
was_published_recently.short_description = _('Published recently?')
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
verbose_name = _('poll')
|
|
|
|
|
verbose_name_plural = _('polls')
|
2013-06-05 01:22:21 +00:00
|
|
|
|
|
|
|
|
|
2014-11-26 15:42:17 +00:00
|
|
|
@python_2_unicode_compatible
|
2013-06-05 01:22:21 +00:00
|
|
|
class Choice(models.Model):
|
2018-05-10 18:36:28 +00:00
|
|
|
poll = models.ForeignKey(
|
|
|
|
|
Poll,
|
|
|
|
|
verbose_name=_('poll'),
|
|
|
|
|
on_delete=models.CASCADE
|
|
|
|
|
)
|
2014-11-26 15:42:17 +00:00
|
|
|
choice_text = models.CharField(
|
|
|
|
|
max_length=200, verbose_name=_('choice text'))
|
2013-07-07 08:15:22 +00:00
|
|
|
votes = models.IntegerField(default=0, verbose_name=_('votes'))
|
2013-06-05 01:22:21 +00:00
|
|
|
|
2014-11-26 15:42:17 +00:00
|
|
|
def __str__(self):
|
2013-06-05 01:22:21 +00:00
|
|
|
return self.choice_text
|
2013-07-07 08:15:22 +00:00
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
|
verbose_name = _('choice')
|
|
|
|
|
verbose_name_plural = _('choices')
|