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',