29 lines
850 B
Python
29 lines
850 B
Python
# Generated by Django 3.0.2 on 2020-02-16 22:09
|
|
from django.db import migrations
|
|
from django_scopes import scopes_disabled
|
|
|
|
|
|
def migrate_ingredients(apps, schema_editor):
|
|
with scopes_disabled():
|
|
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
|
RecipeIngredient = apps.get_model('cookbook', 'RecipeIngredient')
|
|
|
|
for u in RecipeIngredient.objects.values('name').distinct():
|
|
ingredient = Ingredient()
|
|
ingredient.name = u['name']
|
|
ingredient.save()
|
|
|
|
for i in RecipeIngredient.objects.all():
|
|
i.ingredient = Ingredient.objects.get(name=i.name)
|
|
i.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
('cookbook', '0020_recipeingredient_ingredient'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(migrate_ingredients),
|
|
]
|