import - rancher organization linked deploy --> with dashboards of cooperative management oage
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.authentication.api.v1.serializers.serializer import (
|
||||
UserSerializer,
|
||||
OrganizationSerializer,
|
||||
ProvinceSerializer,
|
||||
CitySerializer
|
||||
)
|
||||
from apps.herd.exception import HerdCapacityException
|
||||
from apps.herd.models import Herd, Rancher
|
||||
from rest_framework import serializers
|
||||
from apps.herd.models import Herd, Rancher, RancherOrganizationLink
|
||||
|
||||
|
||||
class HerdSerializer(serializers.ModelSerializer):
|
||||
""" Herd Serializer """
|
||||
|
||||
class Meta:
|
||||
model = Herd
|
||||
fields = '__all__'
|
||||
@@ -49,14 +50,38 @@ class RancherSerializer(serializers.ModelSerializer):
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
representation['province'] = {
|
||||
'id': instance.province.id,
|
||||
'name': instance.province.name
|
||||
}
|
||||
if instance.province:
|
||||
representation['province'] = {
|
||||
'id': instance.province.id,
|
||||
'name': instance.province.name
|
||||
}
|
||||
|
||||
representation['city'] = {
|
||||
'id': instance.city.id,
|
||||
'name': instance.city.name
|
||||
}
|
||||
if instance.city:
|
||||
representation['city'] = {
|
||||
'id': instance.city.id,
|
||||
'name': instance.city.name
|
||||
}
|
||||
|
||||
return representation
|
||||
|
||||
|
||||
class RancherOrganizationLinkSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = RancherOrganizationLink
|
||||
fields = '__all__'
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
if instance.rancher:
|
||||
representation['rancher'] = RancherSerializer(instance.rancher).data
|
||||
|
||||
if instance.organization:
|
||||
representation['organization'] = {
|
||||
"id": instance.organization.id,
|
||||
"name": instance.organization.name,
|
||||
"province": instance.organization.province.name,
|
||||
"city": instance.organization.city.name
|
||||
}
|
||||
|
||||
return representation
|
||||
|
||||
Reference in New Issue
Block a user