# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-04-29 12:47
from __future__ import unicode_literals

from django.db import migrations, models

def fill_levels(apps, schema_editor):
    IPRange = apps.get_model('wdipranges', 'IPRange')
    for r in IPRange.objects.all():
        r.level = int(str(r.cidr).split('/')[1])
        r.save(update_fields=['level'])

def do_nothing(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('wdipranges', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='iprange',
            name='level',
            field=models.IntegerField(default=0),
        ),
        migrations.RunPython(
            fill_levels,
            do_nothing),
    ]
