class FooSerializer(RalphAPISerializer): __str__ = StrField() str_with_type = StrField(show_type=True, label='__str2__') class Meta: model = Foo # include view namespace for hyperlinked field extra_kwargs = {'url': {'view_name': 'test-ralph-api:foo-detail'}}
class ServiceEnvironmentSerializer(RalphAPISerializer): __str__ = StrField(show_type=True) class Meta: model = ServiceEnvironment depth = 1 exclude = ('content_type', 'parent', 'service_env')
class BaseObjectSimpleSerializer(TypeFromContentTypeSerializerMixin, WithCustomFieldsSerializerMixin, RalphAPISerializer): __str__ = StrField(show_type=True) class Meta: model = BaseObject exclude = ('content_type', )
class ConfigurationClassSerializer(TypeFromContentTypeSerializerMixin, WithCustomFieldsSerializerMixin, RalphAPISerializer): __str__ = StrField(show_type=True) module = ConfigurationModuleSimpleSerializer() class Meta: model = ConfigurationClass exclude = ('content_type', 'service_env', 'configuration_path')
class BaseObjectSerializer(RalphAPISerializer): """ Base class for other serializers inheriting from `BaseObject`. """ service_env = ServiceEnvironmentSimpleSerializer() licences = SimpleBaseObjectLicenceSerializer(read_only=True, many=True) __str__ = StrField(show_type=True) class Meta: model = BaseObject exclude = ('content_type', )
class ServiceEnvironmentSerializer(TypeFromContentTypeSerializerMixin, WithCustomFieldsSerializerMixin, RalphAPISerializer): __str__ = StrField(show_type=True) business_owners = SimpleRalphUserSerializer( many=True, source='service.business_owners') technical_owners = SimpleRalphUserSerializer( many=True, source='service.technical_owners') class Meta: model = ServiceEnvironment depth = 1 exclude = ('content_type', 'parent', 'service_env')
class BaseObjectPolymorphicSerializer(TypeFromContentTypeSerializerMixin, PolymorphicSerializer, RalphAPISerializer): """ Serializer for BaseObjects viewset (serialize each model using dedicated serializer). """ __str__ = StrField(show_type=True) service_env = ServiceEnvironmentSerializer() scmstatuscheck = SCMInfoSerializer() class Meta: model = BaseObject exclude = ('content_type', )