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.

44 lines
1.3 KiB

# Generated by Django 2.2.13 on 2020-06-17 19:06
from django.db import migrations, models
import django.db.models.deletion
from seminar.treelib import get_parent
def najdi_cislo(apps, schema_editor):
#
Clanek = apps.get_model('seminar', 'Clanek')
Hodnoceni = apps.get_model('seminar', 'Hodnoceni')
Reseni = apps.get_model('seminar', 'Reseni')
ReseniNode = apps.get_model('seminar', 'ReseniNode')
CisloNode = apps.get_model('seminar', 'CisloNode')
for c in Clanek.objects.all():
reseni = c.reseni_set
if (len(reseni) != 1):
raise ValueError("Článek k sobě má nejedno řešení!")
r = reseni[0]
aktualniNode = r.reseninode
while aktualniNode is not None:
if isinstance(aktualniNode, CisloNode):
c.cislo = aktualniNode.cislo
c.save()
break
aktualniNode = get_parent()
class Migration(migrations.Migration):
dependencies = [
('seminar', '0083_auto_20200506_1952'),
]
operations = [
migrations.AddField(
model_name='clanek',
name='cislo',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='vydane_clanky', to='seminar.Cislo', verbose_name='číslo vydání'),
),
migrations.RunPython(najdi_cislo),
]