From 3bb528f4f1a856285e645f167a025a45d8b51989 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sun, 3 Aug 2025 16:15:12 +0330 Subject: [PATCH] rancher add province & city to serializer --- .idea/Rasaddam_Backend.iml | 2 +- .idea/misc.xml | 2 +- apps/herd/web/api/v1/serializers.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.idea/Rasaddam_Backend.iml b/.idea/Rasaddam_Backend.iml index c5d6090..168bde0 100644 --- a/.idea/Rasaddam_Backend.iml +++ b/.idea/Rasaddam_Backend.iml @@ -14,7 +14,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 29f5506..296aa57 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/apps/herd/web/api/v1/serializers.py b/apps/herd/web/api/v1/serializers.py index 7dd40d9..a7f4293 100644 --- a/apps/herd/web/api/v1/serializers.py +++ b/apps/herd/web/api/v1/serializers.py @@ -31,3 +31,18 @@ class RancherSerializer(serializers.ModelSerializer): class Meta: model = Rancher fields = '__all__' + + def to_representation(self, instance): + representation = super().to_representation(instance) + + representation['province'] = { + 'id': instance.province.id, + 'name': instance.province.name + } + + representation['city'] = { + 'id': instance.city.id, + 'name': instance.city.name + } + + return representation