v1/rating/migrations/0002_django_data_migration_recipe_to_rating.py
# -*- coding: utf-8 -*-
# Generated by Django 2.01 on 2018-06-07
from django.db import migrations
def migrate_rating(apps, schema_editor):
Recipe = apps.get_model('recipe', 'Recipe')
Rating = apps.get_model('rating', 'Rating')
for recipe in Recipe.objects.all():
rating = Rating.objects.create(
recipe=recipe,
author=recipe.author,
rating=recipe.old_rating,
comment='',
)
rating.save()
class Migration(migrations.Migration):
dependencies = [
('rating', '0001_initial'),
('recipe', '0014_auto_20180607_0713'),
]
operations = [
migrations.RunPython(migrate_rating),
]