# Generated by Django 3.0.1 on 2019-12-30 13:51

from django.db import migrations


def move_to_datacontent(apps, schema_editor):
    AssignedContent = apps.get_model("spider_base", "AssignedContent")
    WebConfig = apps.get_model("spider_webcfg", "WebConfig")
    DataContent = apps.get_model("spider_base", "DataContent")

    for assigned in AssignedContent.objects.filter(
        ctype__code=WebConfig._meta.model_name
    ):
        d = DataContent(associated=assigned)
        content = WebConfig.objects.get(id=assigned.object_id)
        d.save()
        assigned.attachedblobs.create(
            unique=True, name="config", blob=content.config
        )


class Migration(migrations.Migration):

    dependencies = [
        ('spider_webcfg', '0003_auto_20190708_1341'),
        ('spider_base', '0011_auto_20191230_1305'),
    ]
    run_before = [
        ('spider_base', '0012_auto_20191230_1305'),
    ]

    operations = [
        migrations.RunPython(move_to_datacontent),
    ]
