Pavel "LEdoian" Turinsky
8 months ago
9 changed files with 79 additions and 21 deletions
@ -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('seminar', '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('seminar', '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 = [ |
|||
('seminar', '0114_related_name_se_zmenilo_a_django_chce_migraci_tak_dostane_migraci'), |
|||
] |
|||
|
|||
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