Browse Source

Migrace: Nefunguje volání metod

Revert souboru seminar/migrations/0002_treenode_nazev.py
export_seznamu_prednasek
Pavel 'LEdoian' Turinsky 5 years ago
parent
commit
418eb7c17a
  1. 104
      seminar/migrations/0002_treenode_nazev.py

104
seminar/migrations/0002_treenode_nazev.py

@ -2,25 +2,95 @@
from django.db import migrations, models
def fix_all_names(apps,schema_editor):
for objtype in [
"RocnikNode",
"CisloNode",
"MezicisloNode",
"TemaVCisleNode",
"KonferaNode",
"ClanekNode",
"UlohaZadaniNode",
"PohadkaNode",
"UlohaVzorakNode",
"TextNode",
]:
Objects = apps.get_model('seminar', objtype)
for obj in Objects.objects.all():
obj.aktualizuj_nazev()
# Better save than sorry
# 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()
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 = [

Loading…
Cancel
Save