Browse Source

Deadline u hodnocení

pull/3/head
Jonas Havelka 2 years ago
parent
commit
e33a80b16d
  1. 35
      seminar/migrations/0104_hodnoceni_deadline_body.py
  2. 3
      seminar/models/odevzdavatko.py

35
seminar/migrations/0104_hodnoceni_deadline_body.py

@ -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),
]

3
seminar/models/odevzdavatko.py

@ -101,6 +101,9 @@ class Hodnoceni(bm.SeminarModelBase):
cislo_body = models.ForeignKey(am.Cislo, verbose_name='číslo pro body',
related_name='hodnoceni', blank=True, null=True, on_delete=models.PROTECT)
deadline_body = models.ForeignKey(am.Deadline, verbose_name='deadline pro body',
related_name='hodnoceni', blank=True, null=True, on_delete=models.PROTECT)
reseni = models.ForeignKey(Reseni, verbose_name='řešení', on_delete=models.CASCADE)
problem = models.ForeignKey(am.Problem, verbose_name='problém',

Loading…
Cancel
Save