DRF override default router path

39 Views Asked by At

When i register viewset in SimpleRouter i get paths like

    [get] objects/
    [post] objects/
    [get] objects/{id}

etc.

Is there a way to replace default post route with its detailed version? like [post] objects/{id}

I've tried to replace it with action in viewset

    @action(detail=True, methods=['post'], url_path="my-path"):
        def my_action:
            ...

but all i've got is

[post] /objects/{id}/my-path

and default post path is still there

Best what i managed is to remove post method from viewset and then add separate APIView explicitly to urls

path("objects/<uuid:project_pk>/", CreateAPIView.as_view()),

But i concerned there is a better way with some router/viewset settings

0

There are 0 best solutions below