# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2016-10-04 16:06
from __future__ import unicode_literals

from django.db import migrations
import csv

def add_person_and_team_data(apps, schema_editor):
    Person = apps.get_model("my_app", "Person")
    Team = apps.get_model("my_app", "Team")
    with open('person.csv') as infile:
        reader = csv.DictReader(infile)
        for row in reader:
            Person.objects.create(id=row["id"], name=row["name"], age=row["year"], eye_color=row["eye_color"])

    with open('data.csv') as infile:
        reader = csv.DictReader(infile)
        for row in reader:
            captain = Person.objects.get(id=row["captain"])
            Team.objects.create(name=row["name"], year=row["year"], captain=captain)


class Migration(migrations.Migration):

    dependencies = [
        ('my_app', '0002_team'),
    ]

    operations = [
        migrations.RunPython(add_person_and_team_data)
    ]
