Nested detail_route in django-rest-framework

Consider a simple view:

class SomeView(viewsets.GenericViewSet, viewsets.mixins.ListModelMixin, viewsets.mixins.RetrieveModelMixin): ... @decorators.detail_route(methods=ENDPOINT_PROPERTY_METHODS) def some_property(self, request, *args, **kwargs): view = SomeOtherView return view.as_view(CRUD_ACTIONS)(request, *args, **kwargs) 

I'm calling SomeOtherView to be able to have an endpoint property, like /someresource/:id/myproperty , so this property will receive a request and can do all CRUD actions.

But I want SomeOtherView have a declared detail_route inside too, to have something like /someresource/:id/myproperty/nestedproperty .
Since I call SomeOtherView dynamically, URLs cannot be registered, so the attached property cannot be called.

How can I resolve this situation to have nested properties?

+6
source share
1 answer

There is currently no own way to automatically create nested routes in the django-rest-framework, but there are some ways to achieve your goal:

Although you did not explain in detail what you want to achieve with the api structure using this structure, I would not continue this path because the views are not intended to be used in this way.

+3
source

Source: https://habr.com/ru/post/987577/


All Articles