# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-12 14:48
#
# Populates parent_author in Page field where possible
#
###############################################################
from __future__ import unicode_literals

from django.db import migrations

def do_stuff(apps, schemd_editor):
    Page = apps.get_model('calligraphy', 'Page').objects
    Work = apps.get_model('calligraphy', 'Work').objects
    Author = apps.get_model('calligraphy', 'Author').objects
    for author in Author.all():
        for work in Work.filter(author=author):
            for page in Page.filter(parent_work=work):
                page.parent_author = author
                page.save()
    


class Migration(migrations.Migration):

    dependencies = [
        ('calligraphy', '0230_page_parent_author'),
    ]

    operations = [ migrations.RunPython(do_stuff)
    ]
