Consider 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 have ability to have an endpoint-property like /someresource/:id/myproperty
, so this property will receive request and can do all CRUD actions.
But, I want to SomeOtherView
to have the declared detail_route
inside too to have something like /someresource/:id/myproperty/nestedproperty
.
Since I'm calling SomeOtherView
dynamically, urls can not be registered, so nested property can not be called.
How I can resolve such situation to have nested properties?
There is currently no native way in automatically creating nested routes in django-rest-framework but there are some ways to achieve your goal:
Although you didn't explain in detail what you want to achive with this api structure I wouldn't recomment continuing this path because views are not intended to be used like that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With