diff options
| author | Tom Christie | 2014-12-19 16:09:01 +0000 |
|---|---|---|
| committer | Tom Christie | 2014-12-19 16:09:01 +0000 |
| commit | d109ae0a2e78551977d93e2507267e43a685fafd (patch) | |
| tree | 156c3d6d999e43c145fcf2da35ec1413c61ae083 /rest_framework/routers.py | |
| parent | 80bacc5fb00682b589b3280c7082af73e3aaa8f8 (diff) | |
| parent | 8f0fef4b75f5c999c13b5d37a263da3a3388142e (diff) | |
| download | django-rest-framework-d109ae0a2e78551977d93e2507267e43a685fafd.tar.bz2 | |
Merge pull request #2010 from tanwanirahul/master
Ability to customize method names without creating a custom router
Diffstat (limited to 'rest_framework/routers.py')
| -rw-r--r-- | rest_framework/routers.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/rest_framework/routers.py b/rest_framework/routers.py index 6e99f14d..1cb65b1c 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -176,23 +176,27 @@ class SimpleRouter(BaseRouter): if isinstance(route, DynamicDetailRoute): # Dynamic detail routes (@detail_route decorator) for httpmethods, methodname in detail_routes: + method_kwargs = getattr(viewset, methodname).kwargs + url_path = method_kwargs.pop("url_path", None) or methodname initkwargs = route.initkwargs.copy() - initkwargs.update(getattr(viewset, methodname).kwargs) + initkwargs.update(method_kwargs) ret.append(Route( - url=replace_methodname(route.url, methodname), + url=replace_methodname(route.url, url_path), mapping=dict((httpmethod, methodname) for httpmethod in httpmethods), - name=replace_methodname(route.name, methodname), + name=replace_methodname(route.name, url_path), initkwargs=initkwargs, )) elif isinstance(route, DynamicListRoute): # Dynamic list routes (@list_route decorator) for httpmethods, methodname in list_routes: + method_kwargs = getattr(viewset, methodname).kwargs + url_path = method_kwargs.pop("url_path", None) or methodname initkwargs = route.initkwargs.copy() - initkwargs.update(getattr(viewset, methodname).kwargs) + initkwargs.update(method_kwargs) ret.append(Route( - url=replace_methodname(route.url, methodname), + url=replace_methodname(route.url, url_path), mapping=dict((httpmethod, methodname) for httpmethod in httpmethods), - name=replace_methodname(route.name, methodname), + name=replace_methodname(route.name, url_path), initkwargs=initkwargs, )) else: |
