diff --git a/shiftregister/app/admin.py b/shiftregister/app/admin.py index 8c38f3f..85a473d 100644 --- a/shiftregister/app/admin.py +++ b/shiftregister/app/admin.py @@ -1,3 +1,10 @@ from django.contrib import admin -# Register your models here. +from .models import Room, Shift, Helper, ShiftRegistration, Message, LoginToken + +admin.site.register(Room) +admin.site.register(Shift) +admin.site.register(Helper) +admin.site.register(ShiftRegistration) +admin.site.register(Message) +admin.site.register(LoginToken) \ No newline at end of file diff --git a/shiftregister/app/apps.py b/shiftregister/app/apps.py index ed327d2..b86d92c 100644 --- a/shiftregister/app/apps.py +++ b/shiftregister/app/apps.py @@ -3,4 +3,4 @@ from django.apps import AppConfig class AppConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' - name = 'app' + name = 'shiftregister.app' diff --git a/shiftregister/app/migrations/0001_initial.py b/shiftregister/app/migrations/0001_initial.py new file mode 100644 index 0000000..cf79448 --- /dev/null +++ b/shiftregister/app/migrations/0001_initial.py @@ -0,0 +1,66 @@ +# Generated by Django 4.0.4 on 2022-04-12 12:19 + +from django.db import migrations, models +import django.db.models.deletion +import shiftregister.app.models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Helper', + fields=[ + ('phone', models.CharField(max_length=200, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=200)), + ('number_validated', models.BooleanField(default=False)), + ], + ), + migrations.CreateModel( + name='Room', + fields=[ + ('name', models.CharField(max_length=200, primary_key=True, serialize=False)), + ('required_helpers', models.IntegerField()), + ], + ), + migrations.CreateModel( + name='Shift', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('start_at', models.DateTimeField()), + ('duration', models.DurationField()), + ('room', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app.room')), + ], + ), + migrations.CreateModel( + name='Message', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('text', models.CharField(max_length=160)), + ('to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.helper')), + ], + ), + migrations.CreateModel( + name='LoginToken', + fields=[ + ('id', models.CharField(default=shiftregister.app.models.gen_token, editable=False, max_length=20, primary_key=True, serialize=False)), + ('helper', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.helper')), + ], + ), + migrations.CreateModel( + name='ShiftRegistration', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('helper', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.helper')), + ('shift', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app.shift')), + ], + options={ + 'unique_together': {('shift', 'helper')}, + }, + ), + ] diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index 71a8362..7f65ba5 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -1,3 +1,46 @@ from django.db import models +import secrets -# Create your models here. +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) \ No newline at end of file diff --git a/shiftregister/settings.py b/shiftregister/settings.py index 3ecf558..19a261d 100644 --- a/shiftregister/settings.py +++ b/shiftregister/settings.py @@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'shiftregister.app.apps.AppConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes',