feat: defect create update时进行限制
This commit is contained in:
parent
9a14216b78
commit
7ad5bad137
|
@ -13,6 +13,16 @@ class DefectSerializer(CustomModelSerializer):
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
read_only_fields = EXCLUDE_FIELDS
|
read_only_fields = EXCLUDE_FIELDS
|
||||||
|
|
||||||
|
def create(self, validated_data):
|
||||||
|
code = validated_data["code"]
|
||||||
|
if Defect.objects.get_queryset(all=True).filter(code=code).exists():
|
||||||
|
raise ValidationError("缺陷标识已存在")
|
||||||
|
return super().create(validated_data)
|
||||||
|
|
||||||
|
def update(self, instance, validated_data):
|
||||||
|
validated_data.pop("code", None)
|
||||||
|
return super().update(instance, validated_data)
|
||||||
|
|
||||||
class TestItemSerializer(CustomModelSerializer):
|
class TestItemSerializer(CustomModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = TestItem
|
model = TestItem
|
||||||
|
|
Loading…
Reference in New Issue