jumpserver/apps/assets/serializers/domain.py

38 lines
1.1 KiB
Python
Raw Normal View History

2018-03-23 11:46:46 +00:00
# -*- coding: utf-8 -*-
#
2020-11-11 02:27:18 +00:00
from django.utils.translation import ugettext_lazy as _
2018-03-23 11:46:46 +00:00
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
from common.drf.fields import ObjectRelatedField
from ..serializers import GatewaySerializer
from ..models import Domain, Asset
__all__ = ['DomainSerializer', 'DomainWithGatewaySerializer']
2018-03-23 11:46:46 +00:00
class DomainSerializer(BulkOrgResourceModelSerializer):
gateways = ObjectRelatedField(
many=True, required=False, queryset=Asset.objects, label=_('Gateway')
)
2022-11-23 10:36:42 +00:00
assets = ObjectRelatedField(
many=True, required=False, queryset=Asset.objects, label=_('Asset')
)
2018-03-23 11:46:46 +00:00
class Meta:
model = Domain
fields_mini = ['id', 'name']
2022-11-23 10:36:42 +00:00
fields_small = fields_mini + ['comment']
fields_m2m = ['assets', 'gateways']
read_only_fields = ['date_created']
2022-11-23 10:36:42 +00:00
fields = fields_small + fields_m2m + read_only_fields
extra_kwargs = {}
2018-03-25 13:47:29 +00:00
class DomainWithGatewaySerializer(BulkOrgResourceModelSerializer):
gateways = GatewaySerializer(many=True, read_only=True)
2018-03-25 13:47:29 +00:00
class Meta:
model = Domain
2018-03-23 11:46:46 +00:00
fields = '__all__'