Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.5 KiB
41 lines
1.5 KiB
9 months ago
|
# 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):
|
||
7 months ago
|
Osoba = apps.get_model('personalni', 'Osoba')
|
||
9 months ago
|
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):
|
||
7 months ago
|
Osoba = apps.get_model('personalni', 'Osoba')
|
||
9 months ago
|
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 = [
|
||
7 months ago
|
('personalni', '0007_post_split_soustredeni'),
|
||
9 months ago
|
]
|
||
|
|
||
|
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',
|
||
|
),
|
||
|
]
|