41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from rest_framework import serializers
|
|
from LiveStock.models import Rancher, LiveStock, LiveStockProduct
|
|
from authentication.serializer.serializer import BankCardSerializer, SystemUserProfileForInspectionSerializer
|
|
from authentication.serializers import SystemAddressSerializer
|
|
|
|
|
|
class RancherSerializer(serializers.ModelSerializer):
|
|
user = SystemUserProfileForInspectionSerializer(read_only=True)
|
|
# address = SystemAddressSerializer(read_only=True)
|
|
|
|
class Meta:
|
|
model = Rancher
|
|
fields = '__all__'
|
|
|
|
|
|
class RancherForBazrasiSerializer(serializers.ModelSerializer):
|
|
heavy_livestock = serializers.SerializerMethodField()
|
|
light_livestock = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = Rancher
|
|
fields = [
|
|
'herd_code',
|
|
'fullname',
|
|
'mobile',
|
|
'lot',
|
|
'lng',
|
|
'heavy_livestock',
|
|
'light_livestock',
|
|
'type'
|
|
|
|
]
|
|
|
|
def get_heavy_livestock(self, obj):
|
|
heavy_counts = self.context.get('heavy_counts') or {}
|
|
return heavy_counts.get(obj.herd_code, 0)
|
|
|
|
def get_light_livestock(self, obj):
|
|
light_counts = self.context.get('light_counts') or {}
|
|
return light_counts.get(obj.herd_code, 0)
|