M&M testovací uživatel na Pavlově notebooku
5 years ago
2 changed files with 47 additions and 1 deletions
@ -0,0 +1,43 @@ |
|||||
|
# 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), |
||||
|
] |
Loading…
Reference in new issue