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.

108 lines
3.6 KiB

5 years ago
# Generated by Django 2.2.5 on 2019-09-26 19:35
from django.db import migrations, models
# Migrace nejspíš neumí volat metody modelů:
# https://stackoverflow.com/questions/28777338/django-migrations-runpython-not-able-to-call-model-methods#37685925
def fix_RocnikNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'RocnikNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.rocnik)+" (RocnikNode)"
obj.save()
def fix_CisloNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'CisloNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.cislo)+" (CisloNode)"
obj.save()
def fix_MezicisloNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'MezicisloNode')
for obj in Objects.objects.all():
if obj.prev:
if (obj.prev.get_real_instance_class() != CisloNode and
obj.prev.get_real_instance_class() != MezicisloNode):
raise ValueError("Předchůdce není číslo!")
posledni = obj.prev.cislo
obj.nazev = "Mezičíslo po čísle"+str(posledni)+" (MezicisloNode)"
elif obj.root:
if obj.root.get_real_instance_class() != RocnikNode:
raise ValueError("Kořen stromu není ročník!")
rocnik = obj.root.rocnik
obj.nazev = "První mezičíslo ročníku "+" (MezicisloNode)"
else:
print("!!!!! Nějaké neidentifikované mezičíslo !!!!!")
obj.nazev = "Neidentifikovatelné mezičíslo! (MezicisloNode)"
obj.save()
def fix_TemaVCisleNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'TemaVCisleNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.tema)+" (TemaVCisleNode)"
obj.save()
def fix_KonferaNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'KonferaNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.konfera)+" (KonferaNode)"
obj.save()
def fix_ClanekNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'ClanekNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.clanek)+" (ClanekNode)"
obj.save()
def fix_UlohaZadaniNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'UlohaZadaniNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.uloha)+" (UlohaZadaniNode)"
obj.save()
def fix_PohadkaNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'PohadkaNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.pohadka)+" (PohadkaNode)"
obj.save()
def fix_UlohaVzorakNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'UlohaVzorakNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.uloha)+" (UlohaVzorakNode)"
obj.save()
def fix_TextNode_names(apps,schema_editor):
Objects = apps.get_model('seminar', 'TextNode')
for obj in Objects.objects.all():
obj.nazev = str(obj.text)+" (TextNode)"
obj.save()
5 years ago
def fix_all_names(apps,schema_editor):
fix_RocnikNode_names(apps,schema_editor)
fix_CisloNode_names(apps,schema_editor)
fix_MezicisloNode_names(apps,schema_editor)
fix_TemaVCisleNode_names(apps,schema_editor)
fix_KonferaNode_names(apps,schema_editor)
fix_ClanekNode_names(apps,schema_editor)
fix_UlohaZadaniNode_names(apps,schema_editor)
fix_PohadkaNode_names(apps,schema_editor)
fix_UlohaVzorakNode_names(apps,schema_editor)
fix_TextNode_names(apps,schema_editor)
5 years ago
class Migration(migrations.Migration):
dependencies = [
('seminar', '0001_reset'),
]
operations = [
migrations.AddField(
model_name='treenode',
name='nazev',
field=models.TextField(help_text='Tento název se zobrazuje v nabídkách pro výběr vhodného TreeNode', null=True, verbose_name='název tohoto node'),
),
migrations.RunPython(fix_all_names),
]