add - import validator for organization quota stats
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from rest_framework import serializers
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
from apps.livestock.web.api.v1.serializers import LiveStockTypeSerializer
|
||||
from apps.product import models as product_models
|
||||
@@ -10,6 +11,13 @@ class QuotaSerializer(serializers.ModelSerializer):
|
||||
model = product_models.Quota
|
||||
fields = '__all__'
|
||||
|
||||
def validate(self, attrs):
|
||||
weight = attrs['quota_weight']
|
||||
if self.instance:
|
||||
if self.instance.quota_distributed < weight:
|
||||
raise APIException("Quota weight cannot be less than distributed weight.")
|
||||
return attrs
|
||||
|
||||
def to_representation(self, instance: product_models.Quota):
|
||||
representation = super().to_representation(instance)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user