# Generated by Django 5.0.2 on 2024-07-22 10:53

from django.db import migrations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from generic.models import ExamUserStatus, CidUserExam

def change_exam_user_status(apps, schema_editor):
    ExamUserStatus: "ExamUserStatus" = apps.get_model("generic", "ExamUserStatus")
    CidUserExam: "CidUserExam" = apps.get_model("generic", "CidUserExam")

    for exam_user_status in ExamUserStatus.objects.all():

        cid_user_exam, created = CidUserExam.objects.get_or_create(content_type=exam_user_status.content_type, object_id=exam_user_status.object_id, user_user=exam_user_status.user_user, cid_user=exam_user_status.cid_user)
        
        exam_user_status.cid_user_exam = cid_user_exam

        exam_user_status.save()

def change_exam_user_status_reverse(apps, schema_editor):
    ExamUserStatus: "ExamUserStatus" = apps.get_model("generic", "ExamUserStatus")
    for exam_user_status in ExamUserStatus.objects.all():
        exam_user_status.cid_user_exam = None
        exam_user_status.save()

class Migration(migrations.Migration):

    dependencies = [
        ('generic', '0014_examuserstatus_cid_user_exam'),
    ]

    operations = [
        migrations.RunPython(change_exam_user_status, change_exam_user_status_reverse)
    ]
