Skip to content

Commit 91de5d7

Browse files
committed
Molnixtag groups into serializers and Admin page
1 parent 0630cc0 commit 91de5d7

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

api/management/commands/sync_molnix.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ def add_tags(molnix_tags, api):
5959
molnix_id=g['id'],
6060
name=g['name'])
6161
if created:
62-
# Bad ide to put these rows into get_or_create, because it would multiply records unnecessary.
63-
# The below 3 rows are optional (just keeps these date parallel with Molnix).
6462
tag_group.created_at = g['created_at']
65-
tag_group.updated_at = g['updated_at']
66-
tag_group.save()
63+
tag_group.updated_at = g['updated_at']
64+
tag_group.save()
6765
tag.groups.add(tag_group)
6866
tag.molnix_id = molnix_tag['id']
6967
tag.name = n = molnix_tag['name']

deployments/admin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ class SectorTagAdmin(CompareVersionAdmin, admin.ModelAdmin):
4646
search_fields = ('title',)
4747

4848

49+
class MolnixTagGroupAdmin(CompareVersionAdmin, admin.ModelAdmin):
50+
model = models.MolnixTagGroup
51+
list_display = ['name', 'molnix_id']
52+
ordering = ('molnix_id',)
53+
search_fields = ('name',)
54+
55+
4956
@admin.register(models.ERU)
5057
class ERUAdmin(CompareVersionAdmin, admin.ModelAdmin):
5158
search_fields = ('national_society_country__name',)
@@ -315,3 +322,4 @@ class EmergencyProjectAdmin(CompareVersionAdmin, admin.ModelAdmin):
315322
admin.site.register(models.ERUReadiness, ERUReadinessAdmin)
316323
admin.site.register(models.Sector, SectorAdmin)
317324
admin.site.register(models.SectorTag, SectorTagAdmin)
325+
admin.site.register(models.MolnixTagGroup, MolnixTagGroupAdmin)

deployments/serializers.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
ERU,
3030
PersonnelDeployment,
3131
MolnixTag,
32+
MolnixTagGroup,
3233
Personnel,
3334
PartnerSocietyActivities,
3435
PartnerSocietyDeployment,
@@ -117,11 +118,18 @@ class Meta:
117118

118119

119120
class MolnixTagSerializer(ModelSerializer):
121+
groups = serializers.SerializerMethodField()
120122

121123
class Meta:
122-
fields = ('id', 'molnix_id', 'name', 'description', 'color', 'tag_type')
124+
fields = ('id', 'molnix_id', 'name', 'description', 'color', 'tag_type', 'groups')
123125
model = MolnixTag
124126

127+
@staticmethod
128+
def get_groups(obj):
129+
return [t.name for t in obj.groups.all() if not t.is_deprecated]
130+
# or a detailed response, if needed:
131+
# return [{"molnix_id": t.molnix_id, "name": t.name} for t in obj.groups.all() if not t.is_deprecated]
132+
125133

126134
class PersonnelDeploymentCsvSerializer(ModelSerializer):
127135
event_deployed_to = SmallEventForPersonnelCsvSerializer()

0 commit comments

Comments
 (0)