A Migration
This commit is contained in:
parent
281c66df11
commit
34b785e235
1 changed files with 104 additions and 0 deletions
104
seminar/migrations/0002_treenode_nazev.py
Normal file
104
seminar/migrations/0002_treenode_nazev.py
Normal file
|
@ -0,0 +1,104 @@
|
|||
# Generated by Django 2.2.5 on 2019-09-26 19:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
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()
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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),
|
||||
]
|
Loading…
Reference in a new issue