Skip to content

Commit 731ee49

Browse files
committed
order sdg by number
1 parent c63e4d3 commit 731ee49

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

api/models/SDG.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class SDG(models.Model):
1313
code = models.CharField(
1414
max_length=10, unique=True, null=False, blank=False
1515
) # e.g., "SDG1", "SDG2"
16+
number = models.IntegerField(
17+
null=True, blank=True
18+
) # Numeric value for proper ordering (1, 2, 3... 17)
1619
description = models.TextField(null=True, blank=True)
1720
slug = models.SlugField(max_length=100, null=True, blank=False, unique=True)
1821

@@ -28,4 +31,4 @@ class Meta:
2831
db_table = "sdg"
2932
verbose_name = "SDG"
3033
verbose_name_plural = "SDGs"
31-
ordering = ["code"]
34+
ordering = ["number"]

api/types/type_sdg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SDGFilter:
2121
class SDGOrder:
2222
"""Order class for SDG model."""
2323

24+
number: auto
2425
code: auto
2526
name: auto
2627

populate_sdgs.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,103 @@
99
SDGS = [
1010
{
1111
"code": "SDG1",
12+
"number": 1,
1213
"name": "No Poverty",
1314
"description": "End poverty in all its forms everywhere",
1415
},
1516
{
1617
"code": "SDG2",
18+
"number": 2,
1719
"name": "Zero Hunger",
1820
"description": "End hunger, achieve food security and improved nutrition and promote sustainable agriculture",
1921
},
2022
{
2123
"code": "SDG3",
24+
"number": 3,
2225
"name": "Good Health and Well-being",
2326
"description": "Ensure healthy lives and promote well-being for all at all ages",
2427
},
2528
{
2629
"code": "SDG4",
30+
"number": 4,
2731
"name": "Quality Education",
2832
"description": "Ensure inclusive and equitable quality education and promote lifelong learning opportunities for all",
2933
},
3034
{
3135
"code": "SDG5",
36+
"number": 5,
3237
"name": "Gender Equality",
3338
"description": "Achieve gender equality and empower all women and girls",
3439
},
3540
{
3641
"code": "SDG6",
42+
"number": 6,
3743
"name": "Clean Water and Sanitation",
3844
"description": "Ensure availability and sustainable management of water and sanitation for all",
3945
},
4046
{
4147
"code": "SDG7",
48+
"number": 7,
4249
"name": "Affordable and Clean Energy",
4350
"description": "Ensure access to affordable, reliable, sustainable and modern energy for all",
4451
},
4552
{
4653
"code": "SDG8",
54+
"number": 8,
4755
"name": "Decent Work and Economic Growth",
4856
"description": "Promote sustained, inclusive and sustainable economic growth, full and productive employment and decent work for all",
4957
},
5058
{
5159
"code": "SDG9",
60+
"number": 9,
5261
"name": "Industry, Innovation and Infrastructure",
5362
"description": "Build resilient infrastructure, promote inclusive and sustainable industrialization and foster innovation",
5463
},
5564
{
5665
"code": "SDG10",
66+
"number": 10,
5767
"name": "Reduced Inequality",
5868
"description": "Reduce inequality within and among countries",
5969
},
6070
{
6171
"code": "SDG11",
72+
"number": 11,
6273
"name": "Sustainable Cities and Communities",
6374
"description": "Make cities and human settlements inclusive, safe, resilient and sustainable",
6475
},
6576
{
6677
"code": "SDG12",
78+
"number": 12,
6779
"name": "Responsible Consumption and Production",
6880
"description": "Ensure sustainable consumption and production patterns",
6981
},
7082
{
7183
"code": "SDG13",
84+
"number": 13,
7285
"name": "Climate Action",
7386
"description": "Take urgent action to combat climate change and its impacts",
7487
},
7588
{
7689
"code": "SDG14",
90+
"number": 14,
7791
"name": "Life Below Water",
7892
"description": "Conserve and sustainably use the oceans, seas and marine resources for sustainable development",
7993
},
8094
{
8195
"code": "SDG15",
96+
"number": 15,
8297
"name": "Life on Land",
8398
"description": "Protect, restore and promote sustainable use of terrestrial ecosystems, sustainably manage forests, combat desertification, and halt and reverse land degradation and halt biodiversity loss",
8499
},
85100
{
86101
"code": "SDG16",
102+
"number": 16,
87103
"name": "Peace, Justice and Strong Institutions",
88104
"description": "Promote peaceful and inclusive societies for sustainable development, provide access to justice for all and build effective, accountable and inclusive institutions at all levels",
89105
},
90106
{
91107
"code": "SDG17",
108+
"number": 17,
92109
"name": "Partnerships for the Goals",
93110
"description": "Strengthen the means of implementation and revitalize the global partnership for sustainable development",
94111
},
@@ -103,7 +120,11 @@ def populate_sdgs() -> None:
103120
for sdg_data in SDGS:
104121
sdg, created = SDG.objects.get_or_create(
105122
code=sdg_data["code"],
106-
defaults={"name": sdg_data["name"], "description": sdg_data["description"]},
123+
defaults={
124+
"name": sdg_data["name"],
125+
"number": sdg_data["number"],
126+
"description": sdg_data["description"],
127+
},
107128
)
108129

109130
if created:
@@ -113,10 +134,12 @@ def populate_sdgs() -> None:
113134
# Update existing SDG if needed
114135
if (
115136
sdg.name != sdg_data["name"]
137+
or sdg.number != sdg_data["number"]
116138
or sdg.description != sdg_data["description"]
117139
):
118-
sdg.name = sdg_data["name"]
119-
sdg.description = sdg_data["description"]
140+
sdg.name = sdg_data["name"] # type: ignore[assignment]
141+
sdg.number = sdg_data["number"] # type: ignore[assignment]
142+
sdg.description = sdg_data["description"] # type: ignore[assignment]
120143
sdg.save()
121144
updated_count += 1
122145
print(f"Updated: {sdg.code} - {sdg.name}")

0 commit comments

Comments
 (0)