feat: 缺陷项分类字段数据库约束放开

This commit is contained in:
caoqianming 2025-04-23 13:46:03 +08:00
parent dd4d958f86
commit e2d63ed056
3 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2025-04-23 05:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('qm', '0049_alter_ptest_sample_number'),
]
operations = [
migrations.AlterField(
model_name='defect',
name='cate',
field=models.CharField(help_text="['尺寸', '外观', '内质', '性能']", max_length=50, verbose_name='分类'),
),
]

View File

@ -14,9 +14,10 @@ class Defect(CommonAModel):
DEFECT_OK = 10
DEFECT_OK_B = 20
DEFECT_NOTOK = 30
cate_list = ["尺寸", "外观", "内质", "性能"]
name = models.CharField(max_length=50, verbose_name="名称")
code = models.CharField(max_length=50, verbose_name="标识", null=True, blank=True)
cate = models.CharField(max_length=50, verbose_name="分类", choices=(("尺寸", "尺寸"), ("外观", "外观"), ("内质", "内质")))
cate = models.CharField(max_length=50, verbose_name="分类", help_text=str(cate_list))
okcate= models.PositiveSmallIntegerField(verbose_name="不合格分类",
choices=((DEFECT_OK, "合格"), (DEFECT_OK_B, "合格B类"), (DEFECT_NOTOK, "不合格")),
default=DEFECT_NOTOK)

View File

@ -15,6 +15,12 @@ class DefectSerializer(CustomModelSerializer):
model = Defect
fields = '__all__'
read_only_fields = EXCLUDE_FIELDS
def validate(self, attrs):
cate = attrs["cate"]
if cate not in Defect.cate_list:
raise ParseError("缺陷类别错误")
return attrs
# def create(self, validated_data):
# code = validated_data["code"]