feat: MlogbDefect 添加count_has 的处理
This commit is contained in:
parent
65d47008a4
commit
a7fd4b9448
|
@ -216,12 +216,17 @@ class MlogbDefectSerializer(CustomModelSerializer):
|
||||||
defect_okcate = serializers.CharField(source="defect.okcate", read_only=True)
|
defect_okcate = serializers.CharField(source="defect.okcate", read_only=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MlogbDefect
|
model = MlogbDefect
|
||||||
fields = ["id", "defect_name", "count", "mlogb", "defect", "defect_okcate"]
|
fields = ["id", "defect_name", "count", "mlogb", "defect", "defect_okcate", "count_has"]
|
||||||
read_only_fields = EXCLUDE_FIELDS_BASE + ["mlogb"]
|
read_only_fields = EXCLUDE_FIELDS_BASE + ["mlogb"]
|
||||||
|
extra_kwargs = {
|
||||||
|
'count_has': {'required': False},
|
||||||
|
}
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
if attrs["count"] < 0:
|
if attrs["count"] < 0:
|
||||||
raise serializers.ValidationError("存在负数!")
|
raise serializers.ValidationError("存在负数!")
|
||||||
|
if "count_has" not in attrs or attrs["count_has"] < attrs["count"]:
|
||||||
|
attrs["count_has"] = attrs["count"]
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
class MlogbSerializer(CustomModelSerializer):
|
class MlogbSerializer(CustomModelSerializer):
|
||||||
|
|
Loading…
Reference in New Issue