Jonas Havelka
2 years ago
4 changed files with 135 additions and 0 deletions
@ -0,0 +1,72 @@ |
|||||
|
# Generated by Django 3.2.15 on 2022-10-01 08:44 |
||||
|
|
||||
|
import datetime |
||||
|
from django.db import migrations, models |
||||
|
import django.db.models.deletion |
||||
|
from django.utils import timezone |
||||
|
|
||||
|
import seminar.models as m |
||||
|
|
||||
|
|
||||
|
def vytvor_deadliny(apps, schema_editor): |
||||
|
Cislo = apps.get_model('seminar', 'Cislo') |
||||
|
Deadline = apps.get_model('seminar', 'Deadline') |
||||
|
|
||||
|
for cislo in Cislo.objects.all(): |
||||
|
if cislo.datum_deadline_soustredeni and cislo.datum_deadline_soustredeni == cislo.datum_preddeadline: |
||||
|
d = Deadline() |
||||
|
d.cislo = cislo |
||||
|
d.typ = m.Deadline.TYP_PRVNI_A_SOUS |
||||
|
d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline_soustredeni, datetime.time.max)) |
||||
|
d.verejna_vysledkovka = cislo.verejna_vysledkovka |
||||
|
d.save() |
||||
|
else: |
||||
|
if cislo.datum_deadline_soustredeni: |
||||
|
d = Deadline() |
||||
|
d.cislo = cislo |
||||
|
d.typ = m.Deadline.TYP_SOUS |
||||
|
d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline_soustredeni, datetime.time.max)) |
||||
|
d.verejna_vysledkovka = cislo.verejna_vysledkovka |
||||
|
d.save() |
||||
|
if cislo.datum_preddeadline: |
||||
|
d = Deadline() |
||||
|
d.cislo = cislo |
||||
|
d.typ = m.Deadline.TYP_PRVNI |
||||
|
d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_preddeadline, datetime.time.max)) |
||||
|
d.verejna_vysledkovka = cislo.verejna_vysledkovka |
||||
|
d.save() |
||||
|
|
||||
|
if cislo.datum_deadline: |
||||
|
d = Deadline() |
||||
|
d.cislo = cislo |
||||
|
d.typ = m.Deadline.TYP_CISLA |
||||
|
d.deadline = timezone.make_aware(datetime.datetime.combine(cislo.datum_deadline, datetime.time.max)) |
||||
|
d.verejna_vysledkovka = cislo.verejna_vysledkovka |
||||
|
d.save() |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('seminar', '0102_osoba_jak_se_dozvedeli'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.CreateModel( |
||||
|
name='Deadline', |
||||
|
fields=[ |
||||
|
('id', models.AutoField(primary_key=True, serialize=False)), |
||||
|
('deadline', models.DateTimeField(default=timezone.make_aware(datetime.datetime.combine(timezone.now(), datetime.time.max)))), |
||||
|
('typ', models.CharField(choices=[('cisla', 'Deadline celého čísla'), ('prvni', 'První deadline'), ('prvniasous', 'Sousový a první deadline'), ('sous', 'Sousový deadline')], max_length=32, verbose_name='typ deadlinu')), |
||||
|
('verejna_vysledkovka', models.BooleanField(db_column='verejna_vysledkovka', default=False, verbose_name='veřejná výsledkovka')), |
||||
|
('cislo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='deadline_v_cisle', to='seminar.cislo', verbose_name='deadline v čísle')), |
||||
|
], |
||||
|
options={ |
||||
|
'verbose_name': 'Deadline', |
||||
|
'verbose_name_plural': 'Deadliny', |
||||
|
'db_table': 'seminar_deadliny', |
||||
|
'ordering': ['deadline'], |
||||
|
}, |
||||
|
), |
||||
|
migrations.RunPython(vytvor_deadliny, migrations.RunPython.noop), |
||||
|
] |
Loading…
Reference in new issue