Jonas Havelka
2 years ago
2 changed files with 38 additions and 0 deletions
@ -0,0 +1,35 @@ |
|||||
|
# Generated by Django 3.2.15 on 2022-10-01 09:28 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
import django.db.models.deletion |
||||
|
from logging import getLogger |
||||
|
|
||||
|
log = getLogger(__name__) |
||||
|
|
||||
|
def prirad_deadliny(apps, schema_editor): |
||||
|
Hodnoceni = apps.get_model('seminar', 'Hodnoceni') |
||||
|
Deadline = apps.get_model('seminar', 'Deadline') |
||||
|
|
||||
|
for h in Hodnoceni.objects.all(): |
||||
|
d = Deadline.objects.filter(deadline__gte=h.reseni.cas_doruceni).first() |
||||
|
h.deadline_body = d |
||||
|
h.save() |
||||
|
|
||||
|
if h.cislo_body and int(h.deadline_body.cislo.poradi) + 1 != int(h.cislo_body.poradi[0]): |
||||
|
log.error(f"Hodnocení {h.id} se špatně změnilo číslo z {h.cislo_body} na {h.deadline_body.cislo}") |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('seminar', '0103_deadline'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AddField( |
||||
|
model_name='hodnoceni', |
||||
|
name='deadline_body', |
||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='hodnoceni', to='seminar.deadline', verbose_name='deadline pro body'), |
||||
|
), |
||||
|
migrations.RunPython(prirad_deadliny, migrations.RunPython.noop), |
||||
|
] |
Loading…
Reference in new issue