Migrace: generování všech RočníkNodů a ČísloNodů
This commit is contained in:
parent
2f50906e6f
commit
de7aae8646
1 changed files with 44 additions and 0 deletions
44
seminar/migrations/0056_vrcholy_pro_rocniky_a_cisla.py
Normal file
44
seminar/migrations/0056_vrcholy_pro_rocniky_a_cisla.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.20 on 2019-05-23 21:54
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
def generuj_RocnikNody_a_CisloNody(apps,schema_editor):
|
||||||
|
Rocnik = apps.get_model('seminar', 'Rocnik')
|
||||||
|
RocnikNode = apps.get_model('seminar', 'RocnikNode')
|
||||||
|
Cislo = apps.get_model('seminar', 'Rocnik')
|
||||||
|
CisloNode = apps.get_model('seminar', 'RocnikNode')
|
||||||
|
|
||||||
|
last_rn = None # last_* slouží k navázání následníků
|
||||||
|
for r in Rocnik.objects.all():
|
||||||
|
rn = RocnikNode.objects.create(rocnik=r)
|
||||||
|
rn.save()
|
||||||
|
rn.root = rn
|
||||||
|
rn.save()
|
||||||
|
if last_rn:
|
||||||
|
last_rn.succ = rn
|
||||||
|
last_rn.save()
|
||||||
|
last_rn = rn
|
||||||
|
|
||||||
|
last_cn = None
|
||||||
|
for c in Cislo.objects.filter(rocnik=r):
|
||||||
|
cn = CisloNode.objects.create(cislo=c, root=rn)
|
||||||
|
cn.save()
|
||||||
|
if last_cn:
|
||||||
|
last_cn.succ = cn
|
||||||
|
last_cn.save()
|
||||||
|
last_cn = cn
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('seminar', '0055_smazat_nemigrovane_zastarale_veci'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(generuj_RocnikNody_a_CisloNody),
|
||||||
|
]
|
Loading…
Reference in a new issue