# Generated by Django 2.1.12 on 2019-09-03 06:17

from django.db import migrations, models


def extract_project_id(apps, schema_editor):
    Project = apps.get_model('project', 'Project')
    for project in Project.objects.all():
        try:
            name_query = project.name.split('-')
            project.number = str(int(name_query[1]))
            project.name = name_query[0].strip()
            project.save(update_fields=['number', 'name'])
        except IndexError:
            pass


class Migration(migrations.Migration):

    dependencies = [
        ('project', '0010_reload_municipalities'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='project',
            name='selected_report',
        ),
        migrations.AddField(
            model_name='project',
            name='number',
            field=models.CharField(blank=True, null=True, unique=True, max_length=10),
        ),
        migrations.RunPython(extract_project_id, reverse_code=migrations.RunPython.noop),
    ]
