Skip to content

Commit 1bfb78e

Browse files
committed
make reference data IDs use consistent casing
1 parent 68216b4 commit 1bfb78e

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Generated by Django 5.2.6 on 2025-09-29 12:47
2+
3+
from django.db import migrations
4+
from django.db.models import Value
5+
from django.db.models.functions import Lower, Replace, Upper
6+
7+
8+
def rename_ids(apps, schema_editor):
9+
SymptomType = apps.get_model("participants", "SymptomType")
10+
SymptomSubType = apps.get_model("participants", "SymptomSubType")
11+
Symptom = apps.get_model("participants", "Symptom")
12+
13+
SymptomType.objects.update(id=Upper(Replace("id", Value("-"), Value("_"))))
14+
SymptomSubType.objects.update(
15+
id=Upper(Replace("id", Value("-"), Value("_"))),
16+
symptom_type=Upper(Replace("symptom_type", Value("-"), Value("_"))),
17+
)
18+
Symptom.objects.update(
19+
symptom_type=Upper(Replace("symptom_type", Value("-"), Value("_")))
20+
)
21+
Symptom.objects.update(
22+
symptom_sub_type=Upper(Replace("symptom_sub_type", Value("-"), Value("_")))
23+
)
24+
25+
26+
def revert_ids(apps, schema_editor):
27+
SymptomType = apps.get_model("participants", "SymptomType")
28+
SymptomSubType = apps.get_model("participants", "SymptomSubType")
29+
Symptom = apps.get_model("participants", "Symptom")
30+
31+
SymptomType.objects.update(id=Lower(Replace("id", Value("_"), Value("-"))))
32+
SymptomSubType.objects.update(
33+
id=Lower(Replace("id", Value("_"), Value("-"))),
34+
symptom_type=Lower(Replace("symptom_type", Value("_"), Value("-"))),
35+
)
36+
Symptom.objects.update(
37+
symptom_type=Lower(Replace("symptom_type", Value("_"), Value("-")))
38+
)
39+
Symptom.objects.update(
40+
symptom_sub_type=Lower(Replace("symptom_sub_type", Value("_"), Value("-")))
41+
)
42+
43+
44+
class Migration(migrations.Migration):
45+
46+
dependencies = [
47+
("participants", "0029_symptom_symptom_sub_type_details"),
48+
]
49+
50+
operations = [
51+
migrations.RunPython(rename_ids, revert_ids),
52+
]

manage_breast_screening/participants/models/symptom.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55

66

77
class SymptomType(ReferenceDataModel):
8-
LUMP = "lump"
9-
SWELLING_OR_SHAPE_CHANGE = "swelling-or-shape-change"
10-
SKIN_CHANGE = "skin-change"
11-
NIPPLE_CHANGE = "nipple-change"
12-
OTHER = "other"
8+
LUMP = "LUMP"
9+
SWELLING_OR_SHAPE_CHANGE = "SWELLING_OR_SHAPE_CHANGE"
10+
SKIN_CHANGE = "SKIN_CHANGE"
11+
NIPPLE_CHANGE = "NIPPLE_CHANGE"
12+
OTHER = "OTHER"
1313

1414
name = models.CharField(null=False, blank=False)
1515

1616

1717
class SymptomSubType(ReferenceDataModel):
18-
SORES_OR_CYSTS = "sores_or_cysts"
19-
DIMPLES_OR_INDENTATION = "dimples_or_indentation"
20-
RASH = "rash"
21-
COLOUR_CHANGE = "colour_change"
22-
OTHER = "other"
18+
SORES_OR_CYSTS = "SORES_OR_CYSTS"
19+
DIMPLES_OR_INDENTATION = "DIMPLES_OR_INDENTATION"
20+
RASH = "RASH"
21+
COLOUR_CHANGE = "COLOUR_CHANGE"
22+
OTHER = "OTHER"
2323

2424
symptom_type = models.ForeignKey(SymptomType, on_delete=models.CASCADE)
2525
name = models.CharField(null=False, blank=False)

0 commit comments

Comments
 (0)