django_analyses.serializers.utils package — django_analyses 0.0.3 documentation

# django_analyses.serializers.utils package

## Submodules

## django_analyses.serializers.utils.polymorphic module

Polymorphic serializer class, copied from: https://stackoverflow.com/questions/48911345/drf-how-to-serialize-models-inheritance-read-write

class `django_analyses.serializers.utils.polymorphic.` `PolymorphicSerializer`(instance=None, data=<class 'rest_framework.fields.empty'>, **kwargs)

  Bases: `rest_framework.serializers.Serializer`

  Serializer to handle multiple subclasses of another class

  - For serialized dict representations, a ‘type’ key with the class name as the value is expected: ex. {‘type’: ‘Decimal’, … }

  - This type information is used in tandem with get_serializer_map(…) to manage serializers for multiple subclasses

  `create`(validated_data)
  `get_serializer`()

    Return a dict to map class names to their respective serializer classes. To be implemented by all PolymorphicSerializer subclasses.

  `get_type`(instance) → str
  `to_internal_value`(data)

    Dict of native values <- Dict of primitive datatypes.

  `to_representation`(instance)

    Object instance -> Dict of primitive datatypes.

  `update`(instance, validated_data)
  `validate_type_key_exists`(data: dict) → None

## Module contents