# Generated by Django 2.2.10 on 2020-05-05 15:01

from django.db import migrations


def noop(apps, schema_editor):  # pragma: no cover
    pass


def populate_category_displayed(apps, schema_editor):  # pragma: no cover
    PollResponseCategory = apps.get_model("polls", "PollResponseCategory")

    updated = 0

    for obj in PollResponseCategory.objects.all().exclude(category=None):
        PollResponseCategory.objects.filter(id=obj.id).update(category_displayed=obj.category)
        updated += 1

    if updated > 0:
        print(f"populated {updated} poll response categories")


class Migration(migrations.Migration):

    dependencies = [
        ("polls", "0059_pollresponsecategory_category_displayed"),
    ]

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

Add migration file