# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-09-27 18:28
from __future__ import unicode_literals

from django.db import migrations, models


def set_next_battery_number(apps, schema_editor):
    Bus = apps.get_model('bus_batteries_app', 'Bus')
    for bus in Bus.objects.all():
        bus.next_battery_number = max(battery.number for battery in bus.battery_set.all()) + 1
        bus.save()


class Migration(migrations.Migration):

    dependencies = [
        ('bus_batteries_app', '0003_remove_battery_id'),
    ]

    operations = [
        migrations.AddField(
            model_name='bus',
            name='next_battery_number',
            field=models.BigIntegerField(default=1),
        ),
        migrations.RunPython(set_next_battery_number),
    ]
