57 lines
1.6 KiB
Python
Executable file
57 lines
1.6 KiB
Python
Executable file
from django.db import models
|
|
from django.contrib.auth.models import AbstractUser
|
|
from django.contrib.auth.models import Group as BuiltinGroup
|
|
|
|
|
|
class User(AbstractUser):
|
|
groups = models.ManyToManyField(
|
|
"auth.Group",
|
|
related_name="user_groups",
|
|
blank=True,
|
|
)
|
|
user_permissions = models.ManyToManyField(
|
|
"auth.Permission",
|
|
related_name="user_permissions",
|
|
blank=True,
|
|
)
|
|
|
|
|
|
class Group(BuiltinGroup):
|
|
class Meta:
|
|
proxy = True
|
|
|
|
|
|
class ReportKind(models.TextChoices):
|
|
WEEKLY = "weekly"
|
|
DAILY = "daily"
|
|
|
|
|
|
class Berichtsheft(models.Model):
|
|
id = models.AutoField(primary_key=True)
|
|
user = models.TextField()
|
|
kind = models.CharField(
|
|
max_length=20, choices=ReportKind.choices, default=ReportKind.WEEKLY
|
|
)
|
|
num = models.PositiveBigIntegerField(default=0)
|
|
year = models.PositiveIntegerField()
|
|
week = models.PositiveSmallIntegerField()
|
|
department = models.CharField(max_length=160, default="")
|
|
content = models.JSONField()
|
|
needs_rewrite = models.BooleanField(default=False)
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
def __str__(self):
|
|
return f"Berichtsheft: {self.user}, Year: {self.year}, Week: {self.week}"
|
|
|
|
@property
|
|
def is_approved(self):
|
|
approvals = Approval.objects.filter(report=self.id)
|
|
return len(approvals) >= 2
|
|
|
|
|
|
class Approval(models.Model):
|
|
id = models.AutoField(primary_key=True)
|
|
user = models.TextField()
|
|
report = models.ForeignKey(
|
|
Berichtsheft, on_delete=models.CASCADE, related_name="report"
|
|
)
|