Browse Source

perf: 修改 serializer

pull/8873/head
ibuler 2 years ago
parent
commit
3e794ec41a
  1. 6
      apps/assets/api/platform.py
  2. 3
      apps/common/drf/serializers.py

6
apps/assets/api/platform.py

@ -2,10 +2,10 @@ from rest_framework.decorators import action
from rest_framework.response import Response
from common.drf.api import JMSModelViewSet
from common.drf.serializers import GroupedChoiceSerailizer
from common.drf.serializers import GroupedChoiceSerializer
from assets.models import Platform
from assets.serializers import PlatformSerializer, PlatformOpsMethodSerializer
from assets.const import AllTypes, Category
from assets.const import AllTypes
from assets.playbooks import filter_platform_methods
@ -16,7 +16,7 @@ class AssetPlatformViewSet(JMSModelViewSet):
queryset = Platform.objects.all()
serializer_classes = {
'default': PlatformSerializer,
'categories': GroupedChoiceSerailizer
'categories': GroupedChoiceSerializer
}
filterset_fields = ['name', 'category', 'type']
search_fields = ['name']

3
apps/common/drf/serializers.py

@ -14,6 +14,7 @@ __all__ = [
'MethodSerializer', 'EmptySerializer', 'BulkModelSerializer',
'AdaptedBulkListSerializer', 'CeleryTaskSerializer',
'SecretReadableMixin', 'JMSWritableNestedModelSerializer',
'GroupedChoiceSerializer',
]
@ -90,7 +91,7 @@ class ChoiceSerializer(serializers.Serializer):
value = serializers.CharField(label=_("Value"))
class GroupedChoiceSerailizer(ChoiceSerializer):
class GroupedChoiceSerializer(ChoiceSerializer):
children = ChoiceSerializer(many=True, label=_("Children"))

Loading…
Cancel
Save