from __future__ import unicode_literals

from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from web.utils.models import DateModel


@python_2_unicode_compatible
class Question(DateModel):
    text = models.TextField(
        verbose_name=_('Question'),
    )
    slug = models.SlugField(
        verbose_name=_('Slug'),
    )
    is_published = models.BooleanField(
        verbose_name=_('Is Published'),
        default=False,
    )

    class Meta(object):
        verbose_name = _('Question')
        verbose_name_plural = _('Question')
        ordering = ['-creation_date']

    def __str__(self):
        return "{}".format(self.text)


@python_2_unicode_compatible
class Choice(DateModel):
    question = models.ForeignKey(
        Question,
        related_name='choices',
        verbose_name=_('Text'),
    )
    text = models.CharField(
        verbose_name=_('Text'),
        max_length=100,
    )

    class Meta(object):
        verbose_name = _('Question choice')
        verbose_name_plural = _('Question choices')
        ordering = ['-creation_date']

    def __str__(self):
        return "{}".format(self.text)
