perf: 资产序列类优化,改为只读

pull/6871/head
ibuler 2021-09-15 17:37:49 +08:00 committed by Jiangjie.Bai
parent 741b96ddee
commit 8e12399058
1 changed files with 12 additions and 8 deletions

View File

@ -75,10 +75,13 @@ class AssetSerializer(BulkOrgResourceModelSerializer):
fields_mini = ['id', 'hostname', 'ip', 'platform', 'protocols'] fields_mini = ['id', 'hostname', 'ip', 'platform', 'protocols']
fields_small = fields_mini + [ fields_small = fields_mini + [
'protocol', 'port', 'protocols', 'is_active', 'public_ip', 'protocol', 'port', 'protocols', 'is_active', 'public_ip',
'comment',
]
hardware_fields = [
'number', 'vendor', 'model', 'sn', 'cpu_model', 'cpu_count', 'number', 'vendor', 'model', 'sn', 'cpu_model', 'cpu_count',
'cpu_cores', 'cpu_vcpus', 'memory', 'disk_total', 'disk_info', 'cpu_cores', 'cpu_vcpus', 'memory', 'disk_total', 'disk_info',
'os', 'os_version', 'os_arch', 'hostname_raw', 'comment', 'os', 'os_version', 'os_arch', 'hostname_raw', 'hardware_info',
'hardware_info', 'connectivity', 'date_verified' 'connectivity', 'date_verified'
] ]
fields_fk = [ fields_fk = [
'domain', 'domain_display', 'platform', 'admin_user', 'admin_user_display' 'domain', 'domain_display', 'platform', 'admin_user', 'admin_user_display'
@ -89,15 +92,16 @@ class AssetSerializer(BulkOrgResourceModelSerializer):
read_only_fields = [ read_only_fields = [
'created_by', 'date_created', 'created_by', 'date_created',
] ]
fields = fields_small + fields_fk + fields_m2m + read_only_fields fields = fields_small + hardware_fields + fields_fk + fields_m2m + read_only_fields
extra_kwargs = { extra_kwargs = {k: {'read_only': True} for k in hardware_fields}
extra_kwargs.update({
'protocol': {'write_only': True}, 'protocol': {'write_only': True},
'port': {'write_only': True}, 'port': {'write_only': True},
'hardware_info': {'label': _('Hardware info')}, 'hardware_info': {'label': _('Hardware info'), 'read_only': True},
'org_name': {'label': _('Org name')}, 'org_name': {'label': _('Org name'), 'read_only': True},
'admin_user_display': {'label': _('Admin user display')} 'admin_user_display': {'label': _('Admin user display'), 'read_only': True},
} })
def get_fields(self): def get_fields(self):
fields = super().get_fields() fields = super().get_fields()