
from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('manager', '0010_auto_20210102_1446'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='set',
            name='exercises',
        ),
    ]


from django.db import migrations


def increment_order(apps, schema_editor):
    """
    Increment the oder in settings so ensure the order is preserved

    Otherwise, and depending on the database, when a set has supersets, the
    exercises could be ordered alphabetically.
    """

    WorkoutSet = apps.get_model("manager", "Set")

    for workout_set in WorkoutSet.objects.all():
        counter = 1
        for exercise in workout_set.exercises.all():
            for setting in workout_set.setting_set.filter(exercise=exercise):
                setting.order = counter
                setting.save()
                counter += 1


class Migration(migrations.Migration):

    dependencies = [
        ('manager', '0010_auto_20210102_1446'),
    ]

    operations = [
        migrations.RunPython(increment_order),
        migrations.RemoveField(
            model_name='set',
            name='exercises',
        ),
    ]

Increment the oder in settings so ensure the order is preserved
Increment the oder in settings so ensure the order is preserved

Otherwise, and depending on the database, when a set has supersets, the
exercises could be ordered alphabetically.

  
  from django.db import migrations
+ 
+ 
+ def increment_order(apps, schema_editor):
+     """
+     Increment the oder in settings so ensure the order is preserved
+ 
+     Otherwise, and depending on the database, when a set has supersets, the
+     exercises could be ordered alphabetically.
+     """
+ 
+     WorkoutSet = apps.get_model("manager", "Set")
+ 
+     for workout_set in WorkoutSet.objects.all():
+         counter = 1
+         for exercise in workout_set.exercises.all():
+             for setting in workout_set.setting_set.filter(exercise=exercise):
+                 setting.order = counter
+                 setting.save()
+                 counter += 1
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('manager', '0010_auto_20210102_1446'),
      ]
  
      operations = [
+         migrations.RunPython(increment_order),
          migrations.RemoveField(
              model_name='set',
              name='exercises',
          ),
      ]
  
Increment the oder in settings so ensure the order is preserved
## Code Before:

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('manager', '0010_auto_20210102_1446'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='set',
            name='exercises',
        ),
    ]

## Instruction:
Increment the oder in settings so ensure the order is preserved
## Code After:

from django.db import migrations


def increment_order(apps, schema_editor):
    """
    Increment the oder in settings so ensure the order is preserved

    Otherwise, and depending on the database, when a set has supersets, the
    exercises could be ordered alphabetically.
    """

    WorkoutSet = apps.get_model("manager", "Set")

    for workout_set in WorkoutSet.objects.all():
        counter = 1
        for exercise in workout_set.exercises.all():
            for setting in workout_set.setting_set.filter(exercise=exercise):
                setting.order = counter
                setting.save()
                counter += 1


class Migration(migrations.Migration):

    dependencies = [
        ('manager', '0010_auto_20210102_1446'),
    ]

    operations = [
        migrations.RunPython(increment_order),
        migrations.RemoveField(
            model_name='set',
            name='exercises',
        ),
    ]
