Skip to content

Viewsets

Async viewset classes plus the ActionConfig dataclass for per-action overrides. See the Viewsets guide and the Action configs guide.

AsyncViewSet

Bases: AsyncViewSetMixin, AsyncAPIView

The base ViewSet class with async dispatch. Does not provide any actions by default.

AsyncGenericViewSet

Bases: AsyncViewSetMixin, AsyncGenericAPIView

The GenericViewSet class with async dispatch. Does not provide any actions by default, but does include the base set of generic view behavior such as aget_object, afilter_queryset, and apaginate_queryset.

AsyncReadOnlyModelViewSet

Bases: AsyncRetrieveModelMixin, AsyncListModelMixin, AsyncGenericViewSet

A viewset that provides default list() and retrieve() actions, served via the async pipeline.

AsyncModelViewSet

Bases: AsyncCreateModelMixin, AsyncRetrieveModelMixin, AsyncUpdateModelMixin, AsyncDestroyModelMixin, AsyncListModelMixin, AsyncGenericViewSet

A viewset that provides default create(), retrieve(), update(), partial_update(), destroy(), and list() actions, served via the async pipeline.

ActionConfig dataclass

ActionConfig(
    serializer_class: type | None = None,
    request_serializer_class: type | None = None,
    response_serializer_class: type | None = None,
    permission_classes: list | tuple | None = None,
    throttle_classes: list | tuple | None = None,
    parser_classes: list | tuple | None = None,
    renderer_classes: list | tuple | None = None,
    pagination_class: type | None = None,
    queryset: Any = None,
)

Per-action override for a viewset. Each field is optional and falls through to the class-level attribute when None. Used as values in action_configs on AsyncViewSet and ViewSet subclasses.

class UserViewSet(AsyncModelViewSet):
    serializer_class = UserSer
    queryset = User.objects.all()
    pagination_class = StandardPagination
    permission_classes = [IsAuthenticated]
    action_configs = {
        "list": ActionConfig(
            serializer_class=UserListSer,
            pagination_class=FastPageNumberPagination,
            queryset=lambda self: User.objects.filter(
                owner=self.request.user
            ),
        ),
        "archive": ActionConfig(
            queryset=User.objects.filter(is_archived=True),
        ),
        "destroy": ActionConfig(permission_classes=[IsAdminUser]),
    }

The queryset field accepts either a static QuerySet or a callable with signature (self) -> QuerySet.