from django.contrib.auth.models import User
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.translation import ugettext_lazy as _


class Task(models.Model):
    CLOSE = 'cl'
    CANCEL = 'ca'
    LATER = 'la'
    UNDEFINED = 'un'
    CHOICES = (
        (UNDEFINED, _("Неизвестно")),
        (CLOSE, _("Завершить")),
        (CANCEL, _("Отменить")),
        (LATER, _("Отложить")),
    )

    title = models.CharField(_("Заголовок"), max_length=50)
    description = models.TextField(_("Описание"))
    executor = models.ForeignKey(User, verbose_name=_("Исполнитель"), on_delete=models.CASCADE)
    status = models.CharField(_("Статус"), choices=CHOICES, default=UNDEFINED, max_length=2)
    deadline = models.DateTimeField(_("Дедлайн"))
    priority = models.IntegerField(_("Приоритет"), default=1, validators=[MinValueValidator(1), MaxValueValidator(3)])
    changed = models.DateTimeField(_("Дата последнего изменения"), auto_now=True)
    created = models.DateTimeField(_("Дата создания"), auto_now_add=True)

    @property
    def text_status(self):
        choices = dict(self.CHOICES)
        return choices[self.status]

    @property
    def text_deadline(self):
        return self.deadline.strftime("%d.%m.%Y %H:%M")


class Comment(models.Model):
    task = models.ForeignKey(Task, related_name="comments", on_delete=models.CASCADE)
    creator = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    text = models.TextField(_('Комментарий'))
    created = models.DateTimeField(_("Дата создания"), auto_now_add=True)

[((39, 11, 39, 85), 'django.db.models.ForeignKey', 'models.ForeignKey', (), '', False, 'from django.db import models\n'), ((40, 14, 40, 75), 'django.db.models.ForeignKey', 'models.ForeignKey', (), '', False, 'from django.db import models\n'), ((19, 29, 19, 52), 'django.utils.translation.ugettext_lazy', '_', ({(19, 31, 19, 51): '"""Заголовок"""'}, {}), "('Заголовок')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((20, 35, 20, 56), 'django.utils.translation.ugettext_lazy', '_', ({(20, 37, 20, 55): '"""Описание"""'}, {}), "('Описание')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((22, 30, 22, 47), 'django.utils.translation.ugettext_lazy', '_', ({(22, 32, 22, 46): '"""Статус"""'}, {}), "('Статус')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((23, 36, 23, 55), 'django.utils.translation.ugettext_lazy', '_', ({(23, 38, 23, 54): '"""Дедлайн"""'}, {}), "('Дедлайн')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((24, 35, 24, 58), 'django.utils.translation.ugettext_lazy', '_', ({(24, 37, 24, 57): '"""Приоритет"""'}, {}), "('Приоритет')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((25, 35, 25, 88), 'django.utils.translation.ugettext_lazy', '_', ({(25, 37, 25, 87): '"""Дата последнего изменения"""'}, {}), "('Дата последнего изменения')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((26, 35, 26, 65), 'django.utils.translation.ugettext_lazy', '_', ({(26, 37, 26, 64): '"""Дата создания"""'}, {}), "('Дата создания')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((41, 28, 41, 55), 'django.utils.translation.ugettext_lazy', '_', ({(41, 30, 41, 54): '"""Комментарий"""'}, {}), "('Комментарий')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((42, 35, 42, 65), 'django.utils.translation.ugettext_lazy', '_', ({(42, 37, 42, 64): '"""Дата создания"""'}, {}), "('Дата создания')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((13, 20, 13, 45), 'django.utils.translation.ugettext_lazy', '_', ({(13, 22, 13, 44): '"""Неизвестно"""'}, {}), "('Неизвестно')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((14, 16, 14, 39), 'django.utils.translation.ugettext_lazy', '_', ({(14, 18, 14, 38): '"""Завершить"""'}, {}), "('Завершить')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((15, 17, 15, 38), 'django.utils.translation.ugettext_lazy', '_', ({(15, 19, 15, 37): '"""Отменить"""'}, {}), "('Отменить')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((16, 16, 16, 37), 'django.utils.translation.ugettext_lazy', '_', ({(16, 18, 16, 36): '"""Отложить"""'}, {}), "('Отложить')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((21, 52, 21, 79), 'django.utils.translation.ugettext_lazy', '_', ({(21, 54, 21, 78): '"""Исполнитель"""'}, {}), "('Исполнитель')", True, 'from django.utils.translation import ugettext_lazy as _\n'), ((24, 83, 24, 103), 'django.core.validators.MinValueValidator', 'MinValueValidator', ({(24, 101, 24, 102): '1'}, {}), '(1)', False, 'from django.core.validators import MaxValueValidator, MinValueValidator\n'), ((24, 105, 24, 125), 'django.core.validators.MaxValueValidator', 'MaxValueValidator', ({(24, 123, 24, 124): '3'}, {}), '(3)', False, 'from django.core.validators import MaxValueValidator, MinValueValidator\n')]