# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


def fill_training_session(apps, schema_editor):
    Note = apps.get_model("documents", "Note")
    for note in Note.objects.filter(training_session=None):
        try:
            session = note.training.trainingsession_set.first()
        except:
            session = note.document.training.trainingsession_set.first()
        note.training_session = session
        note.save()


class Migration(migrations.Migration):

    dependencies = [
        ('documents', '0002_auto_20150421_1529'),
    ]

    operations = [
        migrations.RunPython(fill_training_session),
    ]
