# Generated by Django 2.2.22 on 2021-08-10 13:48

from django.db import migrations


def set_default_school_class(apps, schema_editor):
    Project = apps.get_model('portfolio', 'Project')
    UserSetting = apps.get_model('users', 'UserSetting')
    projects = Project.objects.all()
    bulk_projects = []
    for project in projects:
        owner = project.student
        settings = UserSetting.objects.get(user=owner)
        selected_class = settings.selected_class
        if selected_class is not None:
            project.school_class = selected_class
            bulk_projects.append(project)
    Project.objects.bulk_update(bulk_projects, ['school_class'])


class Migration(migrations.Migration):

    dependencies = [
        ('portfolio', '0005_project_school_class'),
    ]

    operations = [
        migrations.RunPython(set_default_school_class, migrations.RunPython.noop)
    ]
