Browse Source

feat: 资产添加admin_user_display

pull/4086/head
ibuler 5 years ago
parent
commit
a43d6ad34d
  1. 5
      apps/assets/api/asset.py
  2. 4
      apps/assets/models/asset.py
  3. 2
      apps/assets/serializers/asset.py

5
apps/assets/api/asset.py

@ -33,7 +33,10 @@ class AssetViewSet(OrgBulkModelViewSet):
API endpoint that allows Asset to be viewed or edited.
"""
model = Asset
filter_fields = ("hostname", "ip", "systemuser__id", "admin_user__id", "platform__base")
filter_fields = (
"hostname", "ip", "systemuser__id", "admin_user__id", "platform__base",
"is_active"
)
search_fields = ("hostname", "ip")
ordering_fields = ("hostname", "ip", "port", "cpu_cores")
serializer_classes = {

4
apps/assets/models/asset.py

@ -244,6 +244,10 @@ class Asset(ProtocolsMixin, NodesRelationMixin, OrgModelMixin):
def platform_base(self):
return self.platform.base
@lazyproperty
def admin_user_display(self):
return self.admin_user.name
@lazyproperty
def admin_user_username(self):
"""求可连接性时,直接用用户名去取,避免再查一次admin user

2
apps/assets/serializers/asset.py

@ -82,7 +82,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer):
'created_by', 'date_created', 'hardware_info',
]
fields_fk = [
'admin_user', 'domain', 'platform'
'admin_user', 'admin_user_display', 'domain', 'platform'
]
fk_only_fields = {
'platform': ['name']

Loading…
Cancel
Save