mirror of https://github.com/jumpserver/jumpserver
Merge pull request #10729 from jumpserver/pr@dev@perf_custom_asset_support_required_field
perf: 自定义 field 支持 requiredpull/10731/head
commit
54926f7c70
|
@ -49,10 +49,15 @@ def create_serializer_class(serializer_name, fields_info):
|
|||
for i, field_info in enumerate(fields_info):
|
||||
data = {k: field_info.get(k) for k in fields_name}
|
||||
field_type = data.pop('type', 'str')
|
||||
|
||||
if data.get('default') is None:
|
||||
data.pop('default', None)
|
||||
data['required'] = field_info.get('required', True)
|
||||
data = set_default_by_type(field_type, data, field_info)
|
||||
data = set_default_if_need(data, i)
|
||||
if data.get('default', None) is not None:
|
||||
data['required'] = False
|
||||
field_name = data.pop('name')
|
||||
field_class = type_field_map.get(field_type, serializers.CharField)
|
||||
serializer_fields[field_name] = field_class(**data)
|
||||
|
||||
return type(serializer_name, (serializers.Serializer,), serializer_fields)
|
||||
|
|
Loading…
Reference in New Issue