mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-31 20:00:38 -05:00
added recipe steps
This commit is contained in:
47
cookbook/migrations/0062_auto_20200625_2219.py
Normal file
47
cookbook/migrations/0062_auto_20200625_2219.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 20:19
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def create_default_step(apps, schema_editor):
|
||||
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)
|
||||
]
|
||||
Reference in New Issue
Block a user