konova/konova/models/deadline.py
mpeltriaux 65f02c5111 Refactoring
* splits ema/models.py into subpackage
* splits konova/models.py into subpackage
* splits user/models.py into subpackage
2021-11-15 17:41:52 +01:00

50 lines
1.2 KiB
Python

"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 15.11.21
"""
from django.db import models
from django.utils.translation import gettext_lazy as _
from konova.models import BaseResource
class DeadlineType(models.TextChoices):
"""
Django 3.x way of handling enums for models
"""
FINISHED = "finished", _("Finished")
MAINTAIN = "maintain", _("Maintain")
CONTROL = "control", _("Control")
OTHER = "other", _("Other")
class Deadline(BaseResource):
"""
Defines a deadline, which can be used to define dates with a semantic meaning
"""
type = models.CharField(max_length=255, null=True, blank=True, choices=DeadlineType.choices)
date = models.DateField(null=True, blank=True)
comment = models.TextField(null=True, blank=True)
def __str__(self):
return self.type
@property
def type_humanized(self):
""" Returns humanized version of enum
Used for template rendering
Returns:
"""
choices = DeadlineType.choices
for choice in choices:
if choice[0] == self.type:
return choice[1]
return None