Skip to content

FlexFieldsMixin ​

Overview ​

Mixin for DRF ViewSets to add permitted_expands in serializer context based on the current action. Set permit_<action>_expands on the viewset, such as permit_retrieve_expands, to list the fields that action may expand. An action without one allows every expandable field, except list: permit_list_expands defaults to an empty list, so a list request expands nothing until the viewset names fields.

This replaces rest_flex_fields2.views.FlexFieldsMixin and rest_flex_fields2.views.FlexFieldsModelViewSet usage.

get_serializer_context ​

Extend the serializer context with permitted_expands for list actions.

When the current action is list, adds context['permitted_expands'] populated from permit_list_expands so the serializer can restrict expansion accordingly.

Signature ​

get_serializer_context(self)

Parameters ​

NameTypeRequiredDefaultDescription
selfyes

Source ​

server/vueda/core/viewsets/__init__.py:1446

Source ​

server/vueda/core/viewsets/__init__.py:1435