# -*- 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
from django.core.exceptions import ObjectDoesNotExist

def addAdvisor(apps, schemaEditor):
    PhDModel = apps.get_model("academicPhylogeny", "PhD")
    connectionModel = apps.get_model("academicPhylogeny","connection")
    for thePhD in PhDModel.objects.all():
        try:
            theConnection = connectionModel.objects.get(student__id=thePhD.id)
            for advisor in theConnection.advisor.all():
                PhDAdvisor = PhDModel.objects.get(id=advisor.id)
                thePhD.advisor.add(PhDAdvisor)
        except ObjectDoesNotExist:
            pass


class Migration(migrations.Migration):

    dependencies = [
        ('academicPhylogeny', '0006_copy_people_to_PhD'),
    ]

    operations = [
        migrations.RunPython(addAdvisor),
    ]
