Completed
Push — master ( 8a2447...e2760f )
by Paolo
06:42
created

forwards_func()   A

Complexity

Conditions 3

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 24
rs 9.6
c 0
b 0
f 0
cc 3
nop 2
1
# Generated by Django 2.2.9 on 2020-01-29 15:30
2
3
from django.db import migrations
4
5
6
def forwards_func(apps, schema_editor):
7
    # We get the model from the versioned app registry;
8
    # if we directly import it, it'll be the wrong version
9
10
    Animal = apps.get_model(
11
        "uid",
12
        "Animal")
13
14
    Sample = apps.get_model(
15
        "uid",
16
        "Sample")
17
18
    db_alias = schema_editor.connection.alias
19
20
    # Update animal and sample
21
    for animal in Animal.objects.using(db_alias).filter(
22
            alternative_id="fixme"):
23
        animal.alternative_id = animal.name
24
        animal.save()
25
26
    for sample in Sample.objects.using(db_alias).filter(
27
            alternative_id="fixme"):
28
        sample.alternative_id = sample.name
29
        sample.save()
30
31
32
def reverse_func(apps, schema_editor):
33
    """No reverse, cause I can't revert this fields for my animal/samples"""
34
35
    pass
36
37
38
class Migration(migrations.Migration):
39
40
    dependencies = [
41
        ('uid', '0002_auto_20200129_1623'),
42
    ]
43
44
    operations = [
45
        migrations.RunPython(forwards_func, reverse_func),
46
    ]
47