# Generated by Django 3.1.3 on 2020-12-03 13:41

from django.db import migrations, models


def set_channel_name(apps, schema_editor):
    Channel = apps.get_model("observations", "Channel")  # noqa: N806
    for channel in Channel.objects.all():
        if not channel.name:
            channel.name = (
                channel.uniquename if channel.uniquename else f"Channel {channel.id}"
            )
            channel.save(update_fields=["name"])


class Migration(migrations.Migration):

    dependencies = [("observations", "0004_add_null_true_to_channel")]

    operations = [
        migrations.RunPython(set_channel_name, migrations.RunPython.noop),
        migrations.AlterField(
            model_name="channel",
            name="name",
            field=models.CharField(blank=True, max_length=64, verbose_name="Name"),
        ),
        migrations.AlterField(
            model_name="channel",
            name="uniquename",
            field=models.CharField(max_length=64, verbose_name="Unique name for unit"),
        ),
    ]
