Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Rest Framework - detail page of @detail_route

I am ussing @detail_route on my viewsets.ModelViewSet.

class CompanyViewSet(viewsets.ModelViewSet):
    queryset = Company.objects.all()
    serializer_class = serializers.CompanySerializer

    @detail_route(methods=['get', ], permission_classes=[IsCompanyUserPermission, ])
    def accounts(self, request, pk):
    ...
    return Response(...)

# urls.py
router.register(r'companies', views.CompanyViewSet)

this code creates url:

/companies/
/companies/{id}
/companies/{id}/accounts

I dont know how to add route/view to detail account:

/companies/{id}/accounts/{id_account}

Is there any way to add route and views to handle this route ?

(the best option would be add this on CompanyViewSet)

Cheers,

like image 999
user3900778 Avatar asked Sep 18 '14 19:09

user3900778


1 Answers

DRF does not handle nested routes by itself, you may handle it by hand or use an extension, like drf-nested-routers, but its outdated.

My advice : don't fight the framework, DRF is not good at playing with url-nested resources, do it another way.

like image 174
Jocelyn delalande Avatar answered Oct 06 '22 19:10

Jocelyn delalande