# -*- coding: utf-8 -*-
# Generated by Django 1.11.22 on 2019-08-05 17:09
from __future__ import unicode_literals

from django.db import migrations


def migrate_current_issue_types(apps, schema_editor):
    Issue = apps.get_model("journal", "Issue")
    IssueType = apps.get_model("journal", "IssueType")
    for issue in Issue.objects.all():
        if issue.old_issue_type == "Issue":
            issue_type = IssueType.objects.get(
                journal=issue.journal,
                code="issue",
            )
        else:
            issue_type = IssueType.objects.get(
                journal=issue.journal,
                code="collection",
            )
        issue.issue_type = issue_type
        issue.save()


class Migration(migrations.Migration):

    dependencies = [
        ('journal', '0033_migrate_issue_types'),
    ]

    operations = [
        migrations.RunPython(migrate_current_issue_types, reverse_code=migrations.RunPython.noop),
    ]

Migrate issue types on all issues