From af733ecbad1c17839bedefa171a4e7f7b97d977e Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Sun, 17 Sep 2023 16:07:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=B9=B3=E5=8F=B0id?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E5=B1=9E=E6=80=A7=20=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E9=9D=9E=E5=8F=AA=E8=AF=BB=20(#11581)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: feng <1304903146@qq.com> --- apps/assets/serializers/platform.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/assets/serializers/platform.py b/apps/assets/serializers/platform.py index d42eaab19..7960cba88 100644 --- a/apps/assets/serializers/platform.py +++ b/apps/assets/serializers/platform.py @@ -1,6 +1,7 @@ from django.db.models import QuerySet from django.utils.translation import gettext_lazy as _ from rest_framework import serializers +from rest_framework.validators import UniqueValidator from common.serializers import ( WritableNestedModelSerializer, type_field_map, MethodSerializer, @@ -123,6 +124,10 @@ class PlatformSerializer(WritableNestedModelSerializer): ("super", "super 15"), ("super_level", "super level 15") ] + id = serializers.IntegerField( + label='ID', required=False, + validators=[UniqueValidator(queryset=Platform.objects.all())] + ) charset = LabeledChoiceField(choices=Platform.CharsetChoices.choices, label=_("Charset"), default='utf-8') type = LabeledChoiceField(choices=AllTypes.choices(), label=_("Type")) category = LabeledChoiceField(choices=Category.choices, label=_("Category")) @@ -213,7 +218,7 @@ class PlatformSerializer(WritableNestedModelSerializer): def validate_automation(self, automation): automation = automation or {} ansible_enabled = automation.get('ansible_enabled', False) \ - and self.constraints['automation'].get('ansible_enabled', False) + and self.constraints['automation'].get('ansible_enabled', False) automation['ansible_enable'] = ansible_enabled return automation