perf: 修复创建资产时,account 的校验 (#10247)

* perf: 修复创建资产时,account 的校验

* perf: 优化一下提示

---------

Co-authored-by: ibuler <ibuler@qq.com>
pull/10250/head
fit2bot 2 years ago committed by GitHub
parent ca898ed7b5
commit 28f08251b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -53,7 +53,7 @@ class AccountCreateUpdateSerializerMixin(serializers.Serializer):
for data in initial_data: for data in initial_data:
if not data.get('asset') and not self.instance: if not data.get('asset') and not self.instance:
raise serializers.ValidationError({'asset': 'Asset is required'}) raise serializers.ValidationError({'asset': UniqueTogetherValidator.missing_message})
asset = data.get('asset') or self.instance.asset asset = data.get('asset') or self.instance.asset
self.from_template_if_need(data) self.from_template_if_need(data)
self.set_uniq_name_if_need(data, asset) self.set_uniq_name_if_need(data, asset)
@ -111,8 +111,9 @@ class AccountCreateUpdateSerializerMixin(serializers.Serializer):
_validators = super().get_validators() _validators = super().get_validators()
if getattr(self, 'initial_data', None) is None: if getattr(self, 'initial_data', None) is None:
return _validators return _validators
on_invalid = self.initial_data.get('on_invalid') on_invalid = self.initial_data.get('on_invalid')
if on_invalid == AccountInvalidPolicy.ERROR: if on_invalid == AccountInvalidPolicy.ERROR and not self.parent:
return _validators return _validators
_validators = [v for v in _validators if not isinstance(v, UniqueTogetherValidator)] _validators = [v for v in _validators if not isinstance(v, UniqueTogetherValidator)]
return _validators return _validators

Loading…
Cancel
Save