add initial models and enable app
This commit is contained in:
parent
f8a56fb986
commit
85d05299c6
|
@ -1,3 +1,10 @@
|
||||||
from django.contrib import admin
|
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)
|
|
@ -3,4 +3,4 @@ from django.apps import AppConfig
|
||||||
|
|
||||||
class AppConfig(AppConfig):
|
class AppConfig(AppConfig):
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
name = 'app'
|
name = 'shiftregister.app'
|
||||||
|
|
|
@ -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')},
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,3 +1,46 @@
|
||||||
from django.db import models
|
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)
|
|
@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
'shiftregister.app.apps.AppConfig',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
|
|
Loading…
Reference in New Issue