From 671a0490720289e0972c93c6da54d8ee7221105a Mon Sep 17 00:00:00 2001 From: Jonas Havelka Date: Thu, 16 Sep 2021 15:26:02 +0200 Subject: [PATCH] =?UTF-8?q?Osoba=20u=20Organizator=C5=AF=20a=20Resitel?= =?UTF-8?q?=C5=AF=20m=C3=A1=20b=C3=BDt=20povinn=C3=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/migrations/0099_auto_20210916_1509.py | 43 +++++++++++++++++++ seminar/models.py | 8 ++-- 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 seminar/migrations/0099_auto_20210916_1509.py diff --git a/seminar/migrations/0099_auto_20210916_1509.py b/seminar/migrations/0099_auto_20210916_1509.py new file mode 100644 index 00000000..95043d96 --- /dev/null +++ b/seminar/migrations/0099_auto_20210916_1509.py @@ -0,0 +1,43 @@ +# Generated by Django 2.2.24 on 2021-09-16 13:09 + +from django.db import migrations, models +import django.db.models.deletion + + +def force_osoby(apps, schema_editor): + typy_osob = [ + 'Resitel', + 'Organizator' + ] + for typ in typy_osob: + model = apps.get_model('seminar', typ) + pocet = model.objects.filter(osoba=None).count() + if pocet > 0: + # myslím, že je nejde nijak pořádně identifikovat + raise ValueError(str(pocet) + " " + typ + "ů nemá osobu") + + +class Migration(migrations.Migration): + dependencies = [ + ('seminar', '0001_squashed_0098_auto_20210906_0305'), + ] + + operations = [ + migrations.RunPython(force_osoby, migrations.RunPython.noop), + migrations.AlterField( + model_name='organizator', + name='osoba', + field=models.OneToOneField( + help_text='osobní údaje organizátora', + on_delete=django.db.models.deletion.PROTECT, + related_name='org', to='seminar.Osoba', + verbose_name='osoba'), + ), + migrations.AlterField( + model_name='resitel', + name='osoba', + field=models.OneToOneField( + on_delete=django.db.models.deletion.PROTECT, + to='seminar.Osoba', verbose_name='osoba'), + ), + ] diff --git a/seminar/models.py b/seminar/models.py index fdd4de38..ff10348c 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -250,8 +250,8 @@ class Resitel(SeminarModelBase): # Interní ID id = models.AutoField(primary_key = True) - osoba = models.OneToOneField(Osoba, blank=False, null=True, verbose_name='osoba', - on_delete=models.SET_NULL) # FIXME opravit po prvni migraci + osoba = models.OneToOneField(Osoba, blank=False, null=False, verbose_name='osoba', + on_delete=models.PROTECT) skola = models.ForeignKey(Skola, blank=True, null=True, verbose_name='škola', @@ -704,8 +704,8 @@ class Organizator(SeminarModelBase): # zmena dedicnosti z models.Model na SeminarModelBase, potencialni vznik bugu osoba = models.OneToOneField(Osoba, verbose_name='osoba', related_name='org', - help_text='osobní údaje organizátora', null=True, blank=False, - on_delete=models.SET_NULL) #FIXME opravit po migraci + help_text='osobní údaje organizátora', null=False, blank=False, + on_delete=models.PROTECT) vytvoreno = models.DateTimeField( 'Vytvořeno',