I have an application with an API created with DRF. In that i use a DRF-router to route the URL's. I want to add a route to the list-view with parameters (so @list_route won't work) to certain viewsets, but not to others.
So i wanted to define two routers:
user_router = routers.SimpleRouter()
admin_router = routers.SimpleRouter()
I want a route added to one of them:
search_route = Route(
url='^{prefix}/search/(?P<field>\w+)/(?P<value>\w+){trailing_slash}$',
mapping={
'get': 'search',
},
name='{basename}-search',
initkwargs={}
)
admin_router.routes.append(search_route)
But now i end up with the search_route added to both routers, and thus coupled to the viewsets i register in the routers individually.
ipython> user_router.routes
...
Route(url='^{prefix}/search/(?P<field>\\w+)/(?P<method>\\w+)/(?P<keyword>\\w+){trailing_slash}$', mapping={'get': 'search'}, name='{basename}-search', initkwargs={'suffix': 'Search'}),
...
Why is this??? I am probably missing something basic here. How can i add a Route() to certain routers but not to others, so that i can split up my API-urls in "user" and "admin" with each their own methods.