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)