From 944d21f6815ae9c585f37fb63ca7b765d960f770 Mon Sep 17 00:00:00 2001 From: "Andreas (@xAndy) Zimmermann" Date: Wed, 27 Apr 2022 16:19:35 +0200 Subject: [PATCH] dont user helper phne as id anymore. django migrations broke :( --- shiftregister/app/migrations/0001_initial.py | 123 +++++------------- .../app/migrations/0002_logintoken_sent_at.py | 22 ---- .../app/migrations/0003_message_created_at.py | 22 ---- .../0004_shiftregistration_reminder_sent.py | 18 --- .../app/migrations/0005_alter_helper_phone.py | 20 --- .../app/migrations/0006_shift_deleted.py | 18 --- .../app/migrations/0007_alter_helper_phone.py | 25 ---- shiftregister/app/models.py | 2 +- shiftregister/app/views.py | 2 +- .../importer/migrations/0001_initial.py | 37 ++---- 10 files changed, 45 insertions(+), 244 deletions(-) delete mode 100644 shiftregister/app/migrations/0002_logintoken_sent_at.py delete mode 100644 shiftregister/app/migrations/0003_message_created_at.py delete mode 100644 shiftregister/app/migrations/0004_shiftregistration_reminder_sent.py delete mode 100644 shiftregister/app/migrations/0005_alter_helper_phone.py delete mode 100644 shiftregister/app/migrations/0006_shift_deleted.py delete mode 100644 shiftregister/app/migrations/0007_alter_helper_phone.py diff --git a/shiftregister/app/migrations/0001_initial.py b/shiftregister/app/migrations/0001_initial.py index 8cd404d..1178937 100644 --- a/shiftregister/app/migrations/0001_initial.py +++ b/shiftregister/app/migrations/0001_initial.py @@ -1,7 +1,8 @@ -# Generated by Django 4.0.4 on 2022-04-12 12:19 +# Generated by Django 4.0.4 on 2022-04-27 14:11 from django.db import migrations, models import django.db.models.deletion +import phonenumber_field.modelfields import shiftregister.app.models @@ -9,121 +10,63 @@ class Migration(migrations.Migration): initial = True - dependencies = [] + dependencies = [ + ] operations = [ migrations.CreateModel( - name="Helper", + 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)), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('phone', phonenumber_field.modelfields.PhoneNumberField(editable=False, max_length=128, region=None, unique=True)), + ('name', models.CharField(max_length=200)), + ('number_validated', models.BooleanField(default=False)), ], ), migrations.CreateModel( - name="Room", + name='Room', fields=[ - ( - "name", - models.CharField(max_length=200, primary_key=True, serialize=False), - ), - ("required_helpers", models.IntegerField()), + ('name', models.CharField(max_length=200, primary_key=True, serialize=False)), + ('required_helpers', models.IntegerField()), ], ), migrations.CreateModel( - name="Shift", + 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" - ), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('start_at', models.DateTimeField()), + ('duration', models.DurationField()), + ('deleted', models.BooleanField(default=False)), + ('room', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app.room')), ], ), migrations.CreateModel( - name="Message", + 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" - ), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('text', models.CharField(max_length=160)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('to', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.helper')), ], ), migrations.CreateModel( - name="LoginToken", + 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" - ), - ), + ('id', models.CharField(default=shiftregister.app.models.gen_token, editable=False, max_length=20, primary_key=True, serialize=False)), + ('sent_at', models.DateTimeField(auto_now_add=True)), + ('helper', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.helper')), ], ), migrations.CreateModel( - name="ShiftRegistration", + 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" - ), - ), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('reminder_sent', models.BooleanField(default=False)), + ('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")}, + 'unique_together': {('shift', 'helper')}, }, ), ] diff --git a/shiftregister/app/migrations/0002_logintoken_sent_at.py b/shiftregister/app/migrations/0002_logintoken_sent_at.py deleted file mode 100644 index a0544ee..0000000 --- a/shiftregister/app/migrations/0002_logintoken_sent_at.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.0.4 on 2022-04-20 17:01 - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ("app", "0001_initial"), - ] - - operations = [ - migrations.AddField( - model_name="logintoken", - name="sent_at", - field=models.DateTimeField( - auto_now_add=True, default=django.utils.timezone.now - ), - preserve_default=False, - ), - ] diff --git a/shiftregister/app/migrations/0003_message_created_at.py b/shiftregister/app/migrations/0003_message_created_at.py deleted file mode 100644 index 73d9c08..0000000 --- a/shiftregister/app/migrations/0003_message_created_at.py +++ /dev/null @@ -1,22 +0,0 @@ -# Generated by Django 4.0.4 on 2022-04-20 17:06 - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ("app", "0002_logintoken_sent_at"), - ] - - operations = [ - migrations.AddField( - model_name="message", - name="created_at", - field=models.DateTimeField( - auto_now_add=True, default=django.utils.timezone.now - ), - preserve_default=False, - ), - ] diff --git a/shiftregister/app/migrations/0004_shiftregistration_reminder_sent.py b/shiftregister/app/migrations/0004_shiftregistration_reminder_sent.py deleted file mode 100644 index f99e618..0000000 --- a/shiftregister/app/migrations/0004_shiftregistration_reminder_sent.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.0.4 on 2022-04-20 17:57 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("app", "0003_message_created_at"), - ] - - operations = [ - migrations.AddField( - model_name="shiftregistration", - name="reminder_sent", - field=models.BooleanField(default=False), - ), - ] diff --git a/shiftregister/app/migrations/0005_alter_helper_phone.py b/shiftregister/app/migrations/0005_alter_helper_phone.py deleted file mode 100644 index a9a46e9..0000000 --- a/shiftregister/app/migrations/0005_alter_helper_phone.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 4.0.4 on 2022-04-22 00:06 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("app", "0004_shiftregistration_reminder_sent"), - ] - - operations = [ - migrations.AlterField( - model_name="helper", - name="phone", - field=models.CharField( - editable=False, max_length=200, primary_key=True, serialize=False - ), - ), - ] diff --git a/shiftregister/app/migrations/0006_shift_deleted.py b/shiftregister/app/migrations/0006_shift_deleted.py deleted file mode 100644 index 767fa54..0000000 --- a/shiftregister/app/migrations/0006_shift_deleted.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.0.4 on 2022-04-23 00:40 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("app", "0005_alter_helper_phone"), - ] - - operations = [ - migrations.AddField( - model_name="shift", - name="deleted", - field=models.BooleanField(default=False), - ), - ] diff --git a/shiftregister/app/migrations/0007_alter_helper_phone.py b/shiftregister/app/migrations/0007_alter_helper_phone.py deleted file mode 100644 index 48eb5d2..0000000 --- a/shiftregister/app/migrations/0007_alter_helper_phone.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 4.0.4 on 2022-04-27 12:41 - -from django.db import migrations -import phonenumber_field.modelfields - - -class Migration(migrations.Migration): - - dependencies = [ - ("app", "0006_shift_deleted"), - ] - - operations = [ - migrations.AlterField( - model_name="helper", - name="phone", - field=phonenumber_field.modelfields.PhoneNumberField( - editable=False, - max_length=128, - primary_key=True, - region=None, - serialize=False, - ), - ), - ] diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index 0b70ba5..6785efe 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -33,7 +33,7 @@ class Shift(models.Model): class Helper(models.Model): - phone = PhoneNumberField(primary_key=True, editable=False) + phone = PhoneNumberField(unique=True, editable=False) 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) diff --git a/shiftregister/app/views.py b/shiftregister/app/views.py index ff9edd1..e2159e2 100644 --- a/shiftregister/app/views.py +++ b/shiftregister/app/views.py @@ -98,7 +98,7 @@ def register(request): if not form.is_valid(): context["form"] = form return render(request, "register.html", context) - helper = Helper.objects.filter(pk=form.cleaned_data["phone"]).first() + helper = Helper.objects.filter(phone=form.cleaned_data["phone"]).first() if helper: token = helper.logintoken_set.first() # todo: resend login link after x minutes? diff --git a/shiftregister/importer/migrations/0001_initial.py b/shiftregister/importer/migrations/0001_initial.py index d78604b..cbe54ad 100644 --- a/shiftregister/importer/migrations/0001_initial.py +++ b/shiftregister/importer/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.0.4 on 2022-04-23 00:42 +# Generated by Django 4.0.4 on 2022-04-27 14:11 from django.db import migrations, models import django.db.models.deletion @@ -9,41 +9,24 @@ class Migration(migrations.Migration): initial = True dependencies = [ - ("app", "0006_shift_deleted"), + ('app', '0001_initial'), ] operations = [ migrations.CreateModel( - name="Calendar", + name='Calendar', fields=[ - ("url", models.URLField(primary_key=True, serialize=False)), - ("has_errors", models.BooleanField(default=False, editable=False)), + ('url', models.URLField(primary_key=True, serialize=False)), + ('has_errors', models.BooleanField(default=False, editable=False)), ], ), migrations.CreateModel( - name="Event", + name='Event', fields=[ - ( - "shift_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - to="app.shift", - ), - ), - ( - "uuid", - models.UUIDField(editable=False, primary_key=True, serialize=False), - ), - ( - "calendar", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to="importer.calendar", - ), - ), + ('shift_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, to='app.shift')), + ('uuid', models.UUIDField(editable=False, primary_key=True, serialize=False)), + ('calendar', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='importer.calendar')), ], - bases=("app.shift",), + bases=('app.shift',), ), ]