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

from django.db import models, migrations


def fill_training_session(apps, schema_editor):
    WorkshopQuestionUserAnswer = apps.get_model("workshops", "WorkshopQuestionUserAnswer")
    for wqua in WorkshopQuestionUserAnswer.objects.filter(training_session=None):
        wqua.training_session = wqua.question.workshop.training.trainingsession_set.first()
        wqua.save()


class Migration(migrations.Migration):

    dependencies = [
        ('workshops', '0003_merge'),
    ]

    operations = [
        migrations.RunPython(fill_training_session),
    ]
