From 36da9c4dd00ab6f3ce5570b7d2a4a64170f8bc6b Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Thu, 29 Feb 2024 00:06:16 +0100 Subject: [PATCH] Prototypes of Schedule and Slot model --- api_v1/schedule/__init__.py | 0 api_v1/schedule/model.py | 13 +++++++++++++ api_v1/slot/__init__.py | 0 api_v1/slot/model.py | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 api_v1/schedule/__init__.py create mode 100644 api_v1/schedule/model.py create mode 100644 api_v1/slot/__init__.py create mode 100644 api_v1/slot/model.py diff --git a/api_v1/schedule/__init__.py b/api_v1/schedule/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api_v1/schedule/model.py b/api_v1/schedule/model.py new file mode 100644 index 0000000..a68cb8b --- /dev/null +++ b/api_v1/schedule/model.py @@ -0,0 +1,13 @@ +import uuid + +from django.db import models + +from api_v1.profile.model import Profile + + +class Schedule(models.Model): + schedule_id = models.UUIDField(primary_key=True, default=uuid.uuid4) + + profile = models.ForeignKey(Profile, on_delete=models.DO_NOTHING, null=False) + + slots = models.ManyToOneRel() diff --git a/api_v1/slot/__init__.py b/api_v1/slot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api_v1/slot/model.py b/api_v1/slot/model.py new file mode 100644 index 0000000..9a13388 --- /dev/null +++ b/api_v1/slot/model.py @@ -0,0 +1,34 @@ +import uuid + +from django.core.exceptions import ValidationError +from django.db import models + + +def validate_weekday(value: int): + if value < 0 or value > 6: + raise ValidationError("Weekday must be between 0 (Mo) and 6 (Su)") + + +class Slot(models.Model): + slot_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) + + start_time = models.TimeField() + end_time = models.TimeField() + + duration = models.DurationField() + + start_weekday = models.SmallIntegerField(validators=[validate_weekday]) + end_weekday = models.SmallIntegerField(validators=[validate_weekday]) + + def __str__(self): + days = [ + "Mo", + "Tu", + "We", + "Th", + "Fr", + "Sa", + "Su" + ] + return "[{}] {} - [{}] {}".format(days[self.start_weekday], self.start_time, days[self.end_weekday], + self.end_time)