drf nested routers - route subroutine for endpoint

179 Views Asked by At

I have a old endpoint with a URL like this:

url(r'^vehicles/([^/]{1,50})/trips/data/?$', 'vehicle_trip_data'),

which was mapped to my function based view.

I am now refactoring the works to work with drf-nested-routers. What I know is, that I can route to custom methods. Like when I have the former Endpoint url(r'^vehicles/([^/]{1,50})/trips/?$', 'vehicle_trips_view') I am just adding a method trips like this:

@detail_route(methods=['GET'], permission_classes=[IsAuthenticated, VehiclePermissions])
def trips(self, request, pk=None):

I obviously can't just name the method trips/data. So is there a way how I can make a detailed route for the first example!?

1

There are 1 best solutions below

0
On

Try specifying trips/data in url_path parameter.

@detail_route(methods=['GET'], permission_classes=[IsAuthenticated, VehiclePermissions], url_path='trips/data')
def trips(self, request, pk=None):