Skip to content
Next Next commit
Ability to override default method names by customizing it
  • Loading branch information
tanwanirahul committed Nov 3, 2014
commit d972df7c9c1867b4a0a57307f423a488c4d4f4b1
16 changes: 10 additions & 6 deletions rest_framework/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,27 @@ def get_routes(self, viewset):
if isinstance(route, DynamicDetailRoute):
# Dynamic detail routes (@detail_route decorator)
for httpmethods, methodname in detail_routes:
method_kwargs = getattr(viewset, methodname).kwargs
custom_method_name = method_kwargs.pop("custom_method_name", 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, custom_method_name),
mapping=dict((httpmethod, methodname) for httpmethod in httpmethods),
name=replace_methodname(route.name, methodname),
name=replace_methodname(route.name, custom_method_name),
initkwargs=initkwargs,
))
elif isinstance(route, DynamicListRoute):
# Dynamic list routes (@list_route decorator)
for httpmethods, methodname in list_routes:
method_kwargs = getattr(viewset, methodname).kwargs
custom_method_name = method_kwargs.pop("custom_method_name", 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, custom_method_name),
mapping=dict((httpmethod, methodname) for httpmethod in httpmethods),
name=replace_methodname(route.name, methodname),
name=replace_methodname(route.name, custom_method_name),
initkwargs=initkwargs,
))
else:
Expand Down