Jonas Havelka
7 months ago
10 changed files with 93 additions and 21 deletions
@ -0,0 +1,14 @@ |
|||
# Generated by Django 4.2.11 on 2024-04-30 21:53 |
|||
|
|||
from django.db import migrations |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('personalni', '0006_pre_split_soustredeni'), |
|||
('soustredeni', '0003_post_split_soustredeni'), |
|||
] |
|||
|
|||
operations = [ |
|||
] |
@ -0,0 +1,40 @@ |
|||
# Generated by Django 4.2.11 on 2024-04-12 14:03 |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
# V migracích nemáme Osoba.OSLOVENI_*, tak si to sem nakopíruji. |
|||
OSLOVENI_MUZSKE = 'resitel' |
|||
OSLOVENI_ZENSKE = 'resitelka' |
|||
OSLOVENI_ZADNE = '' |
|||
|
|||
def pohlavi_to_osloveni(apps, schema_editor): |
|||
Osoba = apps.get_model('personalni', 'Osoba') |
|||
Osoba.objects.filter(pohlavi_muz=True).update(osloveni=OSLOVENI_MUZSKE) |
|||
Osoba.objects.filter(pohlavi_muz=False).update(osloveni=OSLOVENI_ZENSKE) |
|||
|
|||
def osloveni_to_pohlavi(apps, schema_editor): |
|||
Osoba = apps.get_model('personalni', 'Osoba') |
|||
nebinarni = Osoba.objects.filter(osloveni=OSLOVENI_ZADNE) |
|||
if nebinarni.count() > 0: |
|||
raise Exception("Nelze odmigrovat: v databázi jsou nebinární osoby, které starý model nereprezentuje správně.") |
|||
Osoba.objects.filter(osloveni=OSLOVENI_MUZSKE).update(pohlavi_muz=True) |
|||
Osoba.objects.filter(osloveni=OSLOVENI_MUZSKE).update(pohlavi_muz=False) |
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('personalni', '0007_post_split_soustredeni'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='osoba', |
|||
name='osloveni', |
|||
field=models.CharField(blank=True, choices=[('resitel', 'Řešitel'), ('resitelka', 'Řešitelka')], max_length=32, verbose_name='Oslovení'), |
|||
), |
|||
migrations.RunPython(pohlavi_to_osloveni, osloveni_to_pohlavi), |
|||
migrations.RemoveField( |
|||
model_name='osoba', |
|||
name='pohlavi_muz', |
|||
), |
|||
] |
Loading…
Reference in new issue