# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-19 21:40
from __future__ import unicode_literals

from django.db import migrations


def person2PhD(apps, schema_editor):
    personModel = apps.get_model("academicPhylogeny", "person")
    PhD = apps.get_model("academicPhylogeny", "PhD")
    for person in personModel.objects.all():

        first_middle = []
        if person.firstName:
            first_middle.append(unicode(person.firstName))
        if person.middleName:
            first_middle.append(unicode(person.middleName))

        newObject = PhD(
            id=person.id,
            lastName=person.lastName,
            firstName=" ".join(first_middle),
            year=person.yearOfPhD,
            school=person.school,
            URL_for_detail = (person.firstName + "_" + person.lastName).replace(" ", "_")
                    )
        newObject.save()
        for specialization in person.specialization.all():
            newObject.specialization.add(specialization)
        newObject.save()

class Migration(migrations.Migration):

    dependencies = [
        ('academicPhylogeny', '0005_auto_20170519_2020'),
    ]

    operations = [
        migrations.RunPython(person2PhD),
    ]
