Browse Source
Migrace autora z CharField na odkaz na Organizator Datova migrace: hledani objektu Organizatora, ktery patri ke korekture nebo diskuznimu prispevku. Pokud neni organizator nalezeny tak je SMAZÁN.remotes/origin/korekturovatko_emaily
Bc. Petr Pecha
8 years ago
1 changed files with 58 additions and 0 deletions
@ -0,0 +1,58 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
def transform_autor(apps, schema_editor): |
||||
|
print |
||||
|
Organizator = apps.get_model('seminar', 'Organizator') |
||||
|
|
||||
|
# preorgovani oprav |
||||
|
Oprava = apps.get_model('korektury', 'Oprava') |
||||
|
for oprava in Oprava.objects.all(): |
||||
|
jmeno = oprava.autor.split() |
||||
|
if len(jmeno) == 2: |
||||
|
try: |
||||
|
org = Organizator.objects.get(user__first_name=jmeno[0], |
||||
|
user__last_name=jmeno[1]) |
||||
|
oprava.autor_org = org |
||||
|
oprava.save() |
||||
|
print "{} uložen".format(oprava.autor) |
||||
|
except: |
||||
|
print "Org nenalezen -- mažu korekturu" |
||||
|
# oprava.delete() |
||||
|
else: |
||||
|
print "Org nenalezen -- mažu korekturu" |
||||
|
oprava.delete() |
||||
|
|
||||
|
# preorgovani komentaru |
||||
|
Komentar = apps.get_model('korektury', 'Komentar') |
||||
|
for komentar in Komentar.objects.all(): |
||||
|
jmeno = komentar.autor.split() |
||||
|
if len(jmeno) == 2: |
||||
|
try: |
||||
|
org = Organizator.objects.get(user__first_name=jmeno[0], |
||||
|
user__last_name=jmeno[1]) |
||||
|
komentar.autor_org = org |
||||
|
komentar.save() |
||||
|
print "{} uložen".format(oprava.autor) |
||||
|
except: |
||||
|
print "Org nenalezen -- mažu korekturu" |
||||
|
# oprava.delete() |
||||
|
else: |
||||
|
print "Org nenalezen -- mažu korekturu" |
||||
|
komentar.delete() |
||||
|
|
||||
|
def back(apps, schema_editor): |
||||
|
pass |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('korektury', '0010_Pridani_odkazu_na_organizatora'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.RunPython(transform_autor, back), |
||||
|
] |
Loading…
Reference in new issue