open-eats/openeats-api

View on GitHub
v1/recipe/migrations/0010_auto_20171114_1443.py

Summary

Maintainability
A
0 mins
Test Coverage
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-11-14 20:43
from __future__ import unicode_literals

from django.db import migrations


def create_direction_text(apps, schema_editor):
    Recipe = apps.get_model('recipe', 'Recipe')
    Direction = apps.get_model('recipe', 'Direction')
    for recipe in Recipe.objects.all():
        directions = ''
        for direction in Direction.objects.filter(recipe=recipe).order_by("step"):
            directions += direction.title + "\n"
        recipe.directions = directions
        recipe.save()


class Migration(migrations.Migration):

    dependencies = [
        ('recipe', '0009_auto_20171114_1443'),
    ]

    operations = [
        migrations.RunPython(create_direction_text),
    ]