Mee
6 years ago
1 changed files with 71 additions and 0 deletions
@ -0,0 +1,71 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Generated by Django 1.11.15 on 2019-05-16 20:59 |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
from django.db import migrations |
||||
|
|
||||
|
def spoj_k_organizatorum_osoby(apps, scema_editor): |
||||
|
Organizator = apps.get_model('seminar', 'Organizator') |
||||
|
Resitel = apps.get_model('seminar', 'Resitel') |
||||
|
for org in Organizator.objects.all(): |
||||
|
|
||||
|
# Spárování organizátora s osobou |
||||
|
user = org.user |
||||
|
resitele = Resitel.objects.filter(user=user) |
||||
|
if resitele.count() != 0: |
||||
|
osoba = resitele.first().osoba |
||||
|
else: |
||||
|
osoba = Osoba(user=user) |
||||
|
org.osoba = osoba |
||||
|
|
||||
|
# Přesun informací z organizátora do jeho osoby |
||||
|
osoba.prezdivka = org.prezdivka |
||||
|
osoba.foto = org.foto |
||||
|
osoba.foto_male = org.foto_male |
||||
|
|
||||
|
# Všechno uložit |
||||
|
osoba.save() |
||||
|
org.save() |
||||
|
|
||||
|
def fix_problem(apps, schema_editor): |
||||
|
Problem = apps.get_model('seminar', 'Problem') |
||||
|
Organizator = apps.get_model('seminar', 'Organizator') |
||||
|
for pr in Problem.objects.all(): |
||||
|
if pr.autor_old is not None: |
||||
|
pr.autor = Organizator.objects.filter(osoba__user=pr.autor_old).first() |
||||
|
else: |
||||
|
pr.autor = None |
||||
|
if pr.opravovatel is not None: |
||||
|
pr.opravovatele.add(Organizator.objects.filter(osoba__user=pr.opravovatel).first()) |
||||
|
pr.save() |
||||
|
|
||||
|
def fix_pohadka(apps, schema_editor): |
||||
|
Pohadka = apps.get_model('seminar', 'Pohadka') |
||||
|
Organizator = apps.get_model('seminar', 'Organizator') |
||||
|
for poh in Pohadka.objects.all(): |
||||
|
if poh.autor_old is not None: |
||||
|
poh.autor = Organizator.objects.filter(osoba__user=poh.autor_old).first() |
||||
|
else: |
||||
|
poh.autor = None |
||||
|
poh.save() |
||||
|
|
||||
|
def fix_novinka(apps, schema_editor): |
||||
|
Novinky = apps.get_model('seminar', 'Novinky') |
||||
|
Organizator = apps.get_model('seminar', 'Organizator') |
||||
|
for nov in Novinky.objects.all(): |
||||
|
nov.autor = Organizator.objects.filter(osoba__user=nov.autor_old).first() |
||||
|
|
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('seminar', '0051_resitel_to_osoba'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.RunPython(spoj_k_organizatorum_osoby), |
||||
|
migrations.RunPython(fix_problem), |
||||
|
migrations.RunPython(fix_pohadka), |
||||
|
migrations.RunPython(fix_novinka), |
||||
|
] |
Loading…
Reference in new issue