From bc5494bbb07eda8567d8bd9fe2cff5d3af28b4d9 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 21 Dec 2023 16:45:38 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20label=20choice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/common/serializers/fields.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/common/serializers/fields.py b/apps/common/serializers/fields.py index 4627af85e..282394106 100644 --- a/apps/common/serializers/fields.py +++ b/apps/common/serializers/fields.py @@ -66,10 +66,9 @@ class LabeledChoiceField(ChoiceField): def to_internal_value(self, data): if isinstance(data, dict): data = data.get("value") - if "(" in data and data.endswith(")"): - d = data.strip(")").split('(')[-1] - if d in self.choices: - data = d + + if isinstance(data, str) and "(" in data and data.endswith(")"): + data = data.strip(")").split('(')[-1] return super(LabeledChoiceField, self).to_internal_value(data)