# Generated by Django 3.0.7 on 2020-06-25 20:19

from django.db import migrations, models
from django_scopes import scopes_disabled


def create_default_step(apps, schema_editor):
    with scopes_disabled():
        Recipe = apps.get_model('cookbook', 'Recipe')
        Step = apps.get_model('cookbook', 'Step')

        for r in Recipe.objects.filter(internal=True).all():
            s = Step.objects.create(
                instruction=r.instructions
            )
            for i in r.ingredients.all():
                s.ingredients.add(i)
                s.save()
            r.steps.add(s)
            r.save()


class Migration(migrations.Migration):
    dependencies = [
        ('cookbook', '0061_merge_20200625_2209'),
    ]

    operations = [
        migrations.AlterField(
            model_name='recipe',
            name='ingredients',
            field=models.ManyToManyField(blank=True, to='cookbook.Ingredient'),
        ),
        migrations.CreateModel(
            name='Step',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('kind', models.CharField(choices=[('TEXT', 'Text')], default='TEXT', max_length=16)),
                ('instruction', models.TextField(blank=True)),
                ('ingredients', models.ManyToManyField(blank=True, to='cookbook.Ingredient')),
            ],
        ),
        migrations.AddField(
            model_name='recipe',
            name='steps',
            field=models.ManyToManyField(blank=True, to='cookbook.Step'),
        ),
        migrations.RunPython(create_default_step)
    ]
