Serializers and serializer fields

Additional Django Rest Framework serializers and serializer fields

class vng_api_common.serializers.CacheMixin(*args, **kwargs)

Mixin for Hyperlinked DRF fields to cache the base URI per view, to avoid having to recalculate this for each related object that has to be serialized

This cache is stored on the field instance itself, so it’s reset between requests

get_extra_reverse_kwargs() dict[str, str]

Hook to inject extra kwargs to be passed to reverse()

class vng_api_common.serializers.CachedHyperlinkedIdentityField(*args, **kwargs)

Subclass of serializers.HyperlinkedIdentityField that applies caching in .get_url() to reverse() calls to improve serialization performance

class vng_api_common.serializers.CachedHyperlinkedRelatedField(*args, **kwargs)

Subclass of serializers.HyperlinkedRelatedField that applies caching in .get_url() to reverse() calls to improve serialization performance

class vng_api_common.serializers.CachedNestedHyperlinkedRelatedField(*args, **kwargs)

Subclass of serializers.HyperlinkedIdentityField that applies caching in .get_url() to reverse() calls to improve serialization performance

get_extra_reverse_kwargs() dict[str, str]

Hook to inject extra kwargs to be passed to reverse()

get_url(obj: Model, view_name: str, request: Request, format: str | None) str | None

Given an object, return the URL that hyperlinks to the object.

May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.

class vng_api_common.serializers.FieldValidationErrorSerializer(*args, **kwargs)

Formaat van validatiefouten.

class vng_api_common.serializers.FoutSerializer(*args, **kwargs)

Formaat van HTTP 4xx en 5xx fouten.

class vng_api_common.serializers.GegevensGroepSerializer(*args, **kwargs)

Generate a serializer out of a GegevensGroepType.

Usage:

>>> class VerlengingSerializer(GegevensGroepSerializer):
...     class Meta:
...         model = Zaak
...         gegevensgroep = 'verlenging'
>>>

Where Zaak.verlenging is a :class:GegevensGroepType.

to_internal_value(data)

Pass through the original keys instead of reverse-mapping the source attrs.

to_representation(instance) dict | None

Output the result of accessing the descriptor.

validate_empty_values(data)

Even if we’re in partial-serializer mode, the full gegevensgroep _must_ be provided.

class vng_api_common.serializers.LengthHyperlinkedRelatedField(*args, **kwargs)
to_internal_value(data)

Transform the incoming primitive data into a native value.

class vng_api_common.serializers.NestedGegevensGroepMixin

Set gegevensgroepdata from validated nested data.

Usage: include the mixin on the ModelSerializer that has gegevensgroepen.

create(validated_data)

Handle nested writes.

update(instance, validated_data)

Handle nested writes.

class vng_api_common.serializers.ValidatieFoutSerializer(*args, **kwargs)
vng_api_common.serializers.get_nested_fk_attribute(instance, relation_path)

Retrieves an attribute from a nested foreign key relation.

Args: - instance: The model instance (e.g., Book). - relation_path: A string with the relation path, e.g., ‘author__publisher__name’.

Returns: - The value of the nested attribute or None if not found.