azube/core/models.py

64 lines
1.7 KiB
Python
Raw Normal View History

2024-12-02 16:49:45 +01:00
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth.models import Group as BuiltinGroup
2024-12-03 11:38:13 +01:00
2024-12-02 16:49:45 +01:00
class User(AbstractUser):
groups = models.ManyToManyField(
2024-12-03 11:38:13 +01:00
"auth.Group",
related_name="user_groups",
2024-12-02 16:49:45 +01:00
blank=True,
)
user_permissions = models.ManyToManyField(
2024-12-03 11:38:13 +01:00
"auth.Permission",
related_name="user_permissions",
2024-12-02 16:49:45 +01:00
blank=True,
)
2024-12-03 11:38:13 +01:00
2024-12-02 16:49:45 +01:00
class Group(BuiltinGroup):
class Meta:
proxy = True
2024-12-03 11:38:13 +01:00
2024-12-04 09:37:01 +01:00
class ReportKind(models.TextChoices):
WEEKLY = "weekly"
DAILY = "daily"
2024-12-02 16:49:45 +01:00
class Berichtsheft(models.Model):
id = models.AutoField(primary_key=True)
user = models.TextField()
2024-12-04 09:37:01 +01:00
kind = models.CharField(
max_length=20, choices=ReportKind.choices, default=ReportKind.WEEKLY
)
2024-12-03 11:38:13 +01:00
num = models.PositiveBigIntegerField(default=0)
2024-12-02 16:49:45 +01:00
year = models.PositiveIntegerField()
week = models.PositiveSmallIntegerField()
2024-12-04 09:37:01 +01:00
department = models.CharField(max_length=160, default="")
2024-12-02 16:49:45 +01:00
content = models.JSONField()
2024-12-03 15:15:45 +01:00
needs_rewrite = models.BooleanField(default=False)
2024-12-02 16:49:45 +01:00
created = models.DateTimeField(auto_now_add=True)
def __str__(self):
2024-12-03 13:13:50 +01:00
return f"Berichtsheft: {self.user}, Year: {self.year}, Week: {self.week}"
2024-12-03 11:38:13 +01:00
2024-12-04 11:41:57 +01:00
@property
2024-12-03 15:15:45 +01:00
def is_approved(self):
approvals = Approval.objects.filter(report=self.id)
return len(approvals) >= 2
2024-12-02 16:49:45 +01:00
2024-12-03 15:15:45 +01:00
class Approval(models.Model):
2024-12-02 16:49:45 +01:00
id = models.AutoField(primary_key=True)
user = models.TextField()
2024-12-03 11:38:13 +01:00
report = models.ForeignKey(
Berichtsheft, on_delete=models.CASCADE, related_name="report"
)
2024-12-05 13:45:51 +01:00
class BerichtsheftDraft(models.Model):
user = models.TextField(primary_key=True)
department = models.CharField(max_length=160, default="")
content = models.JSONField()