some changes in quota serializer
This commit is contained in:
@@ -64,7 +64,19 @@ class AttributeValueSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = product_models.AttributeValue
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"attribute",
|
||||
"value",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom Output of attribute values """
|
||||
representation = super().to_representation(instance)
|
||||
if instance.attribute:
|
||||
representation['attribute_name'] = instance.attribute.name
|
||||
|
||||
return representation
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
instance.quota = validated_data.get('quota', instance.quota)
|
||||
|
||||
@@ -10,7 +10,6 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.Quota
|
||||
fields = '__all__'
|
||||
depth = 0
|
||||
|
||||
def to_representation(self, instance):
|
||||
representation = super().to_representation(instance)
|
||||
@@ -40,10 +39,9 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
many=True
|
||||
).data
|
||||
|
||||
representation['limit_by_organizations'] = OrganizationSerializer(
|
||||
instance.limit_by_organizations.all(),
|
||||
many=True
|
||||
).data
|
||||
representation['limit_by_organizations'] = [
|
||||
{"name": limit.name, "id": limit.id} for limit in instance.limit_by_organizations.all()
|
||||
]
|
||||
|
||||
return representation
|
||||
|
||||
@@ -89,7 +87,20 @@ class QuotaStatsSerializer(serializers.ModelSerializer):
|
||||
class QuotaIncentiveAssignmentSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.QuotaIncentiveAssignment
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"incentive_plan",
|
||||
"heavy_value",
|
||||
"light_value",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom Output for incentive plans """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
representation['incentive_plan_name'] = instance.incentive_plan.name
|
||||
|
||||
return representation
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
""" Custom Update """
|
||||
@@ -106,7 +117,19 @@ class QuotaIncentiveAssignmentSerializer(serializers.ModelSerializer):
|
||||
class QuotaBrokerValueSerializer(serializers.ModelSerializer): # noqa
|
||||
class Meta:
|
||||
model = product_models.QuotaBrokerValue
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"broker",
|
||||
"value",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" Custom Output of broker values """
|
||||
|
||||
representation = super().to_representation(instance)
|
||||
representation['broker_name'] = instance.broker.name
|
||||
|
||||
return representation
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
""" Custom Update """
|
||||
@@ -122,7 +145,13 @@ class QuotaBrokerValueSerializer(serializers.ModelSerializer): # noqa
|
||||
class QuotaLiveStockAllocationSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.QuotaLivestockAllocation
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"livestock_group",
|
||||
"livestock_type",
|
||||
"livestock_subtype",
|
||||
"quantity_kg",
|
||||
]
|
||||
extra_kwargs = {
|
||||
'livestock_group': {
|
||||
'required': False
|
||||
@@ -159,7 +188,12 @@ class QuotaLiveStockAllocationSerializer(serializers.ModelSerializer):
|
||||
class QuotaLiveStockAgeLimitationSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = product_models.QuotaLiveStockAgeLimitation
|
||||
fields = '__all__'
|
||||
fields = [
|
||||
"id",
|
||||
"livestock_type",
|
||||
"livestock_subtype",
|
||||
"age_month",
|
||||
]
|
||||
|
||||
def to_representation(self, instance):
|
||||
""" custom output for livestock type """
|
||||
|
||||
Reference in New Issue
Block a user