49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
from django.db import models
|
|
import secrets
|
|
from django.shortcuts import reverse
|
|
|
|
class Room(models.Model):
|
|
name = models.CharField(max_length=200, primary_key=True)
|
|
required_helpers = models.IntegerField()
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
class Shift(models.Model):
|
|
room = models.ForeignKey(Room, on_delete=models.RESTRICT)
|
|
start_at = models.DateTimeField()
|
|
duration = models.DurationField()
|
|
# todo: add helper amount override field
|
|
def __str__(self):
|
|
return f"{self.room.name}: {self.start_at}"
|
|
|
|
class Helper(models.Model):
|
|
# todo: add propper phone number validation, maybe even country code?
|
|
phone = models.CharField(max_length=200, primary_key=True)
|
|
name = models.CharField(max_length=200)
|
|
# change this to a generic state variable to allow for number blocking/account deactivation?
|
|
number_validated = models.BooleanField(default=False)
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
class ShiftRegistration(models.Model):
|
|
class Meta:
|
|
unique_together = (('shift', 'helper'),)
|
|
# use restrict for now as Model.delete is not called
|
|
shift = models.ForeignKey(Shift, on_delete=models.RESTRICT)
|
|
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
|
|
|
class Message(models.Model):
|
|
# remove limit and send long messages in multiple messages?
|
|
text = models.CharField(max_length=160)
|
|
to = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
|
def __str__(self):
|
|
return f"{to.name}: {text}"
|
|
|
|
def gen_token():
|
|
return secrets.token_urlsafe(20)
|
|
|
|
class LoginToken(models.Model):
|
|
id = models.CharField(max_length=20, primary_key=True, default=gen_token, editable=False)
|
|
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
|
|
def get_absolute_url(self):
|
|
return reverse('token_login', kwargs={'token':self.id}) |