# -*- coding: utf-8 -*-
# Generated by Django 1.9.1 on 2016-01-06 13:30
from __future__ import unicode_literals

from django.db import migrations, models


def update_type(apps, schema_editor):
    # Update typ attribute of JednostkaAdministracyjna

    JednostkaAdministracyjna = apps.get_model("teryt",
                                              "JednostkaAdministracyjna")
    LEN_TYPE = {
        7: 'GMI',
        4: 'POW',
        2: 'WOJ',
    }
    for ja in JednostkaAdministracyjna.objects.all():
        ja.typ = LEN_TYPE[len(ja.id)]
        ja.save()


class Migration(migrations.Migration):

    dependencies = [
        ('teryt', '0005_rename_RodzajMiejsowosci'),
    ]

    operations = [
        migrations.AddField(
            model_name='jednostkaadministracyjna',
            name='typ',
            field=models.CharField(blank=True, max_length=3, null=True),
        ),
        migrations.RunPython(update_type),
        migrations.AlterField(
            model_name='jednostkaadministracyjna',
            name='typ',
            field=models.CharField(max_length=3),
        ),
    ]
