# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


def reorder_activities(apps, shema_editor):
    Training = apps.get_model('trainings', 'Training')

    for training in Training.objects.all():
        for index_activity, activity in enumerate(training.activities.order_by('sort_order')):
            activity.sort_order = index_activity
            activity.save()


class Migration(migrations.Migration):

    dependencies = [
        ('trainings', '0021_auto_20150906_1444'),
    ]

    operations = [
        migrations.RunPython(reorder_activities),
        migrations.AlterUniqueTogether(
            name='trainingactivity',
            unique_together=set([('sort_order', 'training')]),
        ),
    ]
