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
|
|
|
|
2022-11-29 09:01:03 +00:00
|
|
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
2022-12-02 03:45:05 +00:00
|
|
|
from common.drf.fields import ObjectRelatedField
|
2022-12-06 03:03:14 +00:00
|
|
|
from ..serializers import GatewaySerializer
|
|
|
|
from ..models import Domain, Asset
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = ['DomainSerializer', 'DomainWithGatewaySerializer']
|
2018-03-23 11:46:46 +00:00
|
|
|
|
|
|
|
|
2019-06-19 08:45:14 +00:00
|
|
|
class DomainSerializer(BulkOrgResourceModelSerializer):
|
2022-12-06 03:03:14 +00:00
|
|
|
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
|
2020-06-16 09:55:18 +00:00
|
|
|
fields_mini = ['id', 'name']
|
2022-11-23 10:36:42 +00:00
|
|
|
fields_small = fields_mini + ['comment']
|
2022-12-06 03:03:14 +00:00
|
|
|
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
|
2022-12-06 03:03:14 +00:00
|
|
|
extra_kwargs = {}
|
2018-03-25 13:47:29 +00:00
|
|
|
|
|
|
|
|
2019-06-19 08:45:14 +00:00
|
|
|
class DomainWithGatewaySerializer(BulkOrgResourceModelSerializer):
|
2022-12-02 09:36:55 +00:00
|
|
|
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__'
|