Total Complexity | 4 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |