diff --git a/apps/assets/api/platform.py b/apps/assets/api/platform.py index e2d85ffbe..bb23abf2d 100644 --- a/apps/assets/api/platform.py +++ b/apps/assets/api/platform.py @@ -5,6 +5,7 @@ from rest_framework import generics from rest_framework import serializers from rest_framework.decorators import action from rest_framework.response import Response + from assets.const import AllTypes from assets.models import Platform, Node, Asset, PlatformProtocol from assets.serializers import PlatformSerializer, PlatformProtocolSerializer, PlatformListSerializer @@ -42,11 +43,16 @@ class AssetPlatformViewSet(JMSModelViewSet): def get_queryset(self): # 因为没有走分页逻辑,所以需要这里 prefetch - asset_count_subquery = Asset.objects.filter(platform=OuterRef('pk')).values('platform').annotate( - count=Count('id')).values('count') - queryset = super().get_queryset().annotate( - assets_amount=Coalesce(Subquery(asset_count_subquery), Value(0))).prefetch_related( - 'protocols', 'automation', 'labels', 'labels__label' + asset_count_subquery = ( + Asset.objects.filter(platform=OuterRef('pk')) + .values('platform') + .annotate(count=Count('id')) + .values('count') + ) + queryset = ( + super().get_queryset() + .annotate(assets_amount=Coalesce(Subquery(asset_count_subquery), Value(0))) + .prefetch_related('protocols', 'automation', 'labels', 'labels__label') ) queryset = queryset.filter(type__in=AllTypes.get_types_values()) return queryset diff --git a/apps/i18n/lina/en.json b/apps/i18n/lina/en.json index d7c0b96c4..c0eeacf8c 100644 --- a/apps/i18n/lina/en.json +++ b/apps/i18n/lina/en.json @@ -315,6 +315,7 @@ "Command": "Command", "CommandConfirm": "Command review", "CommandFilterACL": "Command filter ACL", + "CommandFilterACLs": "Command filter ACLs", "CommandFilter": "Command filter", "CommandFilterACLHelpMsg": "By filtering commands, you can control if commands can be sent to assets. based on your set rules, some commands can be allowed while others are prohibited.", "CommandFilterACLHelpText": "By filtering commands, you can control if commands can be sent to assets. based on your set rules, some commands can be allowed while others are prohibited.",