# Generated by Django 2.2.13 on 2021-01-07 14:53

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


def update_countries(apps, schema_editor):
    # We can't import the Person model directly as it may be a newer
    # version than this migration expects. We use the historical version.
    IU = apps.get_model('dataservices', 'internetusage')
    Country = apps.get_model('dataservices', 'Country')
    for obj in IU.objects.all():
        obj.country = Country.objects.filter(iso3=obj.country_code).first()
        obj.save()


def backward(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('dataservices', '0015_ciafactbook_country'),
    ]

    operations = [
        migrations.AddField(
            model_name='internetusage',
            name='country',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='dataservices.Country'),
        ),
        migrations.RunPython(update_countries, backward),
    ]
