From c357317a517053528b3f813d644c90f82077282e Mon Sep 17 00:00:00 2001 From: vgeffer Date: Sat, 23 Nov 2024 18:50:23 +0100 Subject: [PATCH] Added read-only field id to districts --- personal/serializers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/personal/serializers.py b/personal/serializers.py index 285617d..03c2d61 100644 --- a/personal/serializers.py +++ b/personal/serializers.py @@ -14,9 +14,15 @@ class Meta: @ts_interface(context='personal') class DistrictSerializer(serializers.ModelSerializer): + id = serializers.SerializerMethodField('get_id') + class Meta: model = District - fields = '__all__' + fields = ['id', 'code', 'name', 'abbreviation', 'county'] + read_only_fields = ['id'] + + def get_id(self, obj): + return obj.code @ts_interface(context='personal')