rancher add province & city to serializer
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user