You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jumpserver/apps/assets/serializers/domain.py

38 lines
1.1 KiB

# -*- coding: utf-8 -*-
#
from django.utils.translation import ugettext_lazy as _
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
from common.drf.fields import ObjectRelatedField
from ..serializers import GatewaySerializer
from ..models import Domain, Asset
__all__ = ['DomainSerializer', 'DomainWithGatewaySerializer']
class DomainSerializer(BulkOrgResourceModelSerializer):
gateways = ObjectRelatedField(
many=True, required=False, queryset=Asset.objects, label=_('Gateway')
)
2 years ago
assets = ObjectRelatedField(
many=True, required=False, queryset=Asset.objects, label=_('Asset')
)
class Meta:
model = Domain
fields_mini = ['id', 'name']
2 years ago
fields_small = fields_mini + ['comment']
fields_m2m = ['assets', 'gateways']
read_only_fields = ['date_created']
2 years ago
fields = fields_small + fields_m2m + read_only_fields
extra_kwargs = {}
class DomainWithGatewaySerializer(BulkOrgResourceModelSerializer):
gateways = GatewaySerializer(many=True, read_only=True)
class Meta:
model = Domain
fields = '__all__'