From 8425318ca931cb23faab08df6bf6b65a8e09324d Mon Sep 17 00:00:00 2001 From: Viliam Geffert <60324080+vgeffer@users.noreply.github.com> Date: Sat, 23 Nov 2024 18:54:02 +0100 Subject: [PATCH] Added read-only field id to districts (#441) --- 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')