Passed
Push — master ( 523113...818d71 )
by Peter
02:04
created

reverse()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
1
# -*- coding: utf-8 -*-
2
3
4
from django.db import migrations, models
5
6
def move_max_authors(apps, schema_editor):
7
    Course = apps.get_model("opensubmit", "Course")
8
    for course in Course.objects.all():
9
        max_authors=course.max_authors
10
        for assignment in course.assignments.all():
11
            assignment.max_authors=max_authors
12
            print("Setting max authors for assignment '{0}' in course '{1}'...".format(assignment.title, course.title))
13
            assignment.save()
14
15
def reverse(apps, schema_editor):
16
    Assignment = apps.get_model("opensubmit", "Assignment")
17
    for ass in Assignment.objects.all():
18
        ass.max_authors=1 # default
19
        ass.save()
20
21
class Migration(migrations.Migration):
22
23
    dependencies = [
24
        ('opensubmit', '0021_auto_20171011_2218'),
25
    ]
26
27
    operations = [
28
        migrations.AddField(
29
            model_name='assignment',
30
            name='max_authors',
31
            field=models.PositiveSmallIntegerField(default=1, help_text=b'Maximum number of authors (= group size) for this assignment.'),
32
        ),
33
        migrations.RunPython(move_max_authors, reverse),
34
    ]
35