Jonas Havelka
4 weeks ago
4 changed files with 50 additions and 9 deletions
@ -0,0 +1,41 @@ |
|||||
|
# Generated by Django 4.2.13 on 2024-06-11 23:53 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
def pridej_orgy(apps, schema_editor): |
||||
|
PDF = apps.get_model('korektury', 'KorekturovanePDF') |
||||
|
for pdf in PDF.objects.all(): # Tohle by asi mělo jít udělat pomocí update, ale moc práce a rychlé hledání taky nepomohlo. |
||||
|
if pdf.org is not None: pdf.orgove.add(pdf.org) |
||||
|
pdf.save() # ig? |
||||
|
|
||||
|
def vyber_orga(apps, schema_editor): |
||||
|
PDF = apps.get_model('korektury', 'KorekturovanePDF') |
||||
|
for pdf in PDF.objects.all(): |
||||
|
orgove = pdf.orgove.all() |
||||
|
if len(orgove) > 1: |
||||
|
raise migrations.exceptions.IrreversibleError(f'PDF {pdf.id} má víc než jednoho zodpovědného orga, nejde odmigrovat na verzi, která umí jen jednoho.') |
||||
|
if len(orgove) == 0: |
||||
|
pdf.org = None |
||||
|
else: |
||||
|
pdf.org = orgove[0] |
||||
|
pdf.save() |
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('personalni', '0011_osloveni_vsechny_choices'), |
||||
|
('korektury', '0023_personalni_post_migrate'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AddField( |
||||
|
model_name='korekturovanepdf', |
||||
|
name='orgove', |
||||
|
field=models.ManyToManyField(blank=True, default=None, help_text='Zodpovědní organizátoři za obsah (chodí jim maily o nových korekturách)', to='personalni.organizator'), |
||||
|
), |
||||
|
migrations.RunPython(pridej_orgy, vyber_orga), |
||||
|
migrations.RemoveField( |
||||
|
model_name='korekturovanepdf', |
||||
|
name='org', |
||||
|
), |
||||
|
] |
Loading…
Reference in new issue