Skip to content

Commit 6927c2f

Browse files
committed
Add CharacteristicGroup model see HEA-874
1 parent 2690fe5 commit 6927c2f

2 files changed

Lines changed: 150 additions & 3 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Generated by Django 5.2.7 on 2026-01-26 06:44
2+
3+
import django.db.models.deletion
4+
import django.utils.timezone
5+
import model_utils.fields
6+
from django.db import migrations, models
7+
8+
import common.fields
9+
10+
11+
def forwards(apps, schema_editor):
12+
WealthCharacteristic = apps.get_model("metadata", "WealthCharacteristic")
13+
WealthCharacteristic.objects.update(characteristic_group=None)
14+
15+
16+
class Migration(migrations.Migration):
17+
18+
dependencies = [
19+
("metadata", "0013_wealthcharacteristic_characteristic_group"),
20+
]
21+
22+
operations = [
23+
migrations.RunPython(
24+
code=forwards,
25+
reverse_code=migrations.RunPython.noop,
26+
),
27+
migrations.CreateModel(
28+
name="CharacteristicGroup",
29+
fields=[
30+
(
31+
"created",
32+
model_utils.fields.AutoCreatedField(
33+
default=django.utils.timezone.now, editable=False, verbose_name="created"
34+
),
35+
),
36+
(
37+
"modified",
38+
model_utils.fields.AutoLastModifiedField(
39+
default=django.utils.timezone.now, editable=False, verbose_name="modified"
40+
),
41+
),
42+
(
43+
"code",
44+
common.fields.CodeField(max_length=60, primary_key=True, serialize=False, verbose_name="Code"),
45+
),
46+
(
47+
"ordering",
48+
models.PositiveSmallIntegerField(
49+
blank=True,
50+
help_text="The order to display the items in when sorting by this field, if not obvious.",
51+
null=True,
52+
verbose_name="Ordering",
53+
),
54+
),
55+
(
56+
"aliases",
57+
models.JSONField(
58+
blank=True,
59+
help_text="A list of alternate names for the object.",
60+
null=True,
61+
verbose_name="aliases",
62+
),
63+
),
64+
("name_en", common.fields.NameField(max_length=60, verbose_name="Name")),
65+
("name_fr", common.fields.NameField(blank=True, max_length=60, verbose_name="Name")),
66+
("name_es", common.fields.NameField(blank=True, max_length=60, verbose_name="Name")),
67+
("name_pt", common.fields.NameField(blank=True, max_length=60, verbose_name="Name")),
68+
("name_ar", common.fields.NameField(blank=True, max_length=60, verbose_name="Name")),
69+
(
70+
"description_en",
71+
common.fields.DescriptionField(
72+
blank=True,
73+
help_text="Any extra information or detail that is relevant to the object.",
74+
max_length=2000,
75+
verbose_name="Description",
76+
),
77+
),
78+
(
79+
"description_fr",
80+
common.fields.DescriptionField(
81+
blank=True,
82+
help_text="Any extra information or detail that is relevant to the object.",
83+
max_length=2000,
84+
verbose_name="Description",
85+
),
86+
),
87+
(
88+
"description_es",
89+
common.fields.DescriptionField(
90+
blank=True,
91+
help_text="Any extra information or detail that is relevant to the object.",
92+
max_length=2000,
93+
verbose_name="Description",
94+
),
95+
),
96+
(
97+
"description_pt",
98+
common.fields.DescriptionField(
99+
blank=True,
100+
help_text="Any extra information or detail that is relevant to the object.",
101+
max_length=2000,
102+
verbose_name="Description",
103+
),
104+
),
105+
(
106+
"description_ar",
107+
common.fields.DescriptionField(
108+
blank=True,
109+
help_text="Any extra information or detail that is relevant to the object.",
110+
max_length=2000,
111+
verbose_name="Description",
112+
),
113+
),
114+
],
115+
options={
116+
"verbose_name": "Characteristic Group",
117+
"verbose_name_plural": "Characteristic Groups",
118+
},
119+
),
120+
migrations.AlterField(
121+
model_name="wealthcharacteristic",
122+
name="characteristic_group",
123+
field=models.ForeignKey(
124+
blank=True,
125+
db_column="characteristic_group", # Add this line
126+
help_text="Optional grouping for characteristics, such as 'Population', 'Income', 'Land', 'Livestock', 'Other assets'",
127+
null=True,
128+
on_delete=django.db.models.deletion.PROTECT,
129+
to="metadata.characteristicgroup",
130+
verbose_name="Characteristic Group",
131+
),
132+
),
133+
]

apps/metadata/models.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ class Meta:
115115
verbose_name_plural = _("Livelihood Categories")
116116

117117

118+
class CharacteristicGroup(ReferenceData):
119+
"""
120+
A grouping for Wealth Characteristics, such as 'Population', 'Income', 'Land', 'Livestock', 'Other assets'.
121+
"""
122+
123+
objects = IdentifierManager.from_queryset(ReferenceDataQuerySet)()
124+
125+
class Meta:
126+
verbose_name = _("Characteristic Group")
127+
verbose_name_plural = _("Characteristic Groups")
128+
129+
118130
class WealthCharacteristic(ReferenceData):
119131
"""
120132
A Characteristic of a Wealth Group, such as `Number of children at school`, etc.
@@ -154,14 +166,16 @@ class VariableType(models.TextChoices):
154166
default=VariableType.STR,
155167
help_text=_("Whether the field is numeric, character, boolean, etc."),
156168
)
157-
characteristic_group = models.CharField(
158-
max_length=20,
169+
characteristic_group = models.ForeignKey(
170+
CharacteristicGroup,
171+
db_column="characteristic_group",
159172
blank=True,
160173
null=True,
174+
on_delete=models.PROTECT,
161175
verbose_name=_("Characteristic Group"),
162176
help_text=_(
163177
"Optional grouping for characteristics, such as 'Population', 'Income', "
164-
"'Land', 'Livestock', 'Poultry', 'Other assets'"
178+
"'Land', 'Livestock', 'Other assets'"
165179
),
166180
)
167181
objects = IdentifierManager.from_queryset(ReferenceDataQuerySet)()

0 commit comments

Comments
 (0)