# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-01-05 16:33
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

    dependencies = [
        ('iati', '0062_activity_publisher'),
    ]

    def starworst(apps, schema_editor):
        try: # don't run on first migration
            Activity = apps.get_model('iati', 'Activity')
            Dataset = apps.get_model('iati', 'Dataset')
        except:
            return

        for d in Dataset.objects.all():
            Activity.objects.filter(dataset=d).update(publisher=d.publisher)


    operations = [
        migrations.RunPython(starworst, lambda x,y: None),
        migrations.AlterField(
            model_name='activity',
            name='publisher',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='iati_synchroniser.Publisher'),
        ),
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2017-01-05 16:33
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

    dependencies = [
        ('iati', '0062_activity_publisher'),
    ]

    def starworst(apps, schema_editor):
        try: # don't run on first migration
            Activity = apps.get_model('iati', 'Activity')
            Dataset = apps.get_model('iati_synchroniser', 'Dataset')
        except:
            return

        for d in Dataset.objects.all():
            Activity.objects.filter(dataset=d).update(publisher=d.publisher)


    operations = [
        migrations.RunPython(starworst, lambda x,y: None),
        migrations.AlterField(
            model_name='activity',
            name='publisher',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='iati_synchroniser.Publisher'),
        ),
    ]

fix data migrations