Osoba u Organizatorů a Resitelů má být povinná
This commit is contained in:
parent
e5c0878c7f
commit
671a049072
2 changed files with 47 additions and 4 deletions
43
seminar/migrations/0099_auto_20210916_1509.py
Normal file
43
seminar/migrations/0099_auto_20210916_1509.py
Normal file
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -250,8 +250,8 @@ class Resitel(SeminarModelBase):
|
||||||
# Interní ID
|
# Interní ID
|
||||||
id = models.AutoField(primary_key = True)
|
id = models.AutoField(primary_key = True)
|
||||||
|
|
||||||
osoba = models.OneToOneField(Osoba, blank=False, null=True, verbose_name='osoba',
|
osoba = models.OneToOneField(Osoba, blank=False, null=False, verbose_name='osoba',
|
||||||
on_delete=models.SET_NULL) # FIXME opravit po prvni migraci
|
on_delete=models.PROTECT)
|
||||||
|
|
||||||
|
|
||||||
skola = models.ForeignKey(Skola, blank=True, null=True, verbose_name='škola',
|
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
|
# zmena dedicnosti z models.Model na SeminarModelBase, potencialni vznik bugu
|
||||||
|
|
||||||
osoba = models.OneToOneField(Osoba, verbose_name='osoba', related_name='org',
|
osoba = models.OneToOneField(Osoba, verbose_name='osoba', related_name='org',
|
||||||
help_text='osobní údaje organizátora', null=True, blank=False,
|
help_text='osobní údaje organizátora', null=False, blank=False,
|
||||||
on_delete=models.SET_NULL) #FIXME opravit po migraci
|
on_delete=models.PROTECT)
|
||||||
|
|
||||||
vytvoreno = models.DateTimeField(
|
vytvoreno = models.DateTimeField(
|
||||||
'Vytvořeno',
|
'Vytvořeno',
|
||||||
|
|
Loading…
Reference in a new issue