# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-06-26 07:56
from __future__ import unicode_literals

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


def migrate_component_indicators_data(apps, schema_editor):
    """
        Adds the Indicator object from Component.indicator to the
        many-to-many relationship in Component.indicators
    """
    Component = apps.get_model('goals', 'Component')

    for component in Component.objects.select_related('indicator').iterator():
        component.indicators.add(component.indicator)


class Migration(migrations.Migration):

    dependencies = [
        ('goals', '0019_alter_field_type_on_area_allow_blank'),
    ]

    operations = [
        migrations.AddField(
            model_name='component',
            name='indicators',
            field=models.ManyToManyField(related_name='components', to='goals.Indicator', verbose_name='Indicators'),
        ),
        migrations.AlterField(
            model_name='component',
            name='indicator',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='components_old', to='goals.Indicator', verbose_name='Indicator'),
        ),
        migrations.RunPython(migrate_component_indicators_data),
    ]
