# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-10-27 11:59
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

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

    def split_quotas(apps, schema):
        Department = apps.get_model('academic', 'Department')
        Category = apps.get_model('academic', 'Category')

        categories = Category.objects.filter(is_quoted=True)
        for department in Department.objects.all():
            for category in categories:
                department.quotas.create(category=category, qty=department.quota)


    operations = [
        migrations.CreateModel(
            name='Quota',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('qty', models.IntegerField(default=4, verbose_name='Квота на участие')),
                ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quotas', to='academic.Category', verbose_name='Категория')),
                ('department', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='quotas', to='academic.Department', verbose_name='Подразделение')),
            ],
        ),
        migrations.RunPython(split_quotas)
    ]
