# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2017-06-08 09:54
from __future__ import unicode_literals

import logging

from django.db import migrations, models
import django.db.models.deletion


logger = logging.getLogger(__name__)


def copy_iati_to_aims(apps, *args):
    """
    Copy the field values from the iati models to the aims models
    """
    models = ['AidTypeFlag', 'AidTypeCategory', 'AidType']
    for model in models:
        old_model = apps.get_model('iati', model)
        new_model = apps.get_model('aims', model)
        for old in old_model.objects.all():
            serialized = old.__dict__
            del serialized['_state']
            new_model.objects.create(**serialized)


class Migration(migrations.Migration):

    dependencies = [
        ('aims', '0031_auto_20170525_1623'),
    ]

    operations = [
        migrations.CreateModel(
            name='AidType',
            fields=[
                ('code', models.CharField(max_length=3, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField()),
            ],
        ),
        migrations.CreateModel(
            name='AidTypeCategory',
            fields=[
                ('code', models.CharField(max_length=3, primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=200)),
                ('description', models.TextField()),
            ],
        ),
        migrations.CreateModel(
            name='AidTypeFlag',
            fields=[
                ('code', models.SmallIntegerField(primary_key=True, serialize=False)),
                ('name', models.CharField(max_length=100)),
            ],
        ),
        migrations.AddField(
            model_name='aidtype',
            name='category',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='aims.AidTypeCategory'),
        ),
        migrations.RunPython(copy_iati_to_aims)
    ]
