---
url: "https://vueda.dev/v3/reference/api/py/vueda.core.viewsets/FlexFieldsMixin.md"
title: "FlexFieldsMixin"
---

# 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` {#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-signature}

`get_serializer_context(self)`

#### Parameters {#get_serializer_context-parameters}

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| self |  | yes |  |  |

### Source {#get_serializer_context-source}

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

## Source

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