Skip to content

Supporting additional methods for a viewset's list route #7851

Discussion options

You must be logged in to vote

@adamckay we ended up going with a bit of a work around. Our use case is a bulk update endpoint at something like PATCH /v1/list-resource

We have the normal viewset class like

class SomeResourceViewSet(viewsets.ViewSet):
    ...
    # note: do NOT add the @action decorator
    def bulk_update(self, request): ...

Apparently the ViewSet.as_view method allows passing in a dict of action names to method handlers, so we ended up generating a custom view from the viewset like

fixed_resource_list_view = SomeResourceViewSet.as_view(
    {
        "get": "list",
        "post": "create",
        "patch": "bulk_update",
    }
)

Then assign this view it as the first item in urlpatterns to override t…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@adamckay
Comment options

Answer selected by auvipy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants