mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
Allow dynamic routes to set 'serialzer_class' kwarg.
This commit is contained in:
parent
22569e8202
commit
1c7ca24c02
|
@ -171,7 +171,7 @@ class SimpleRouter(BaseRouter):
|
|||
method_kwargs = getattr(viewset, methodname).kwargs
|
||||
initkwargs = route.initkwargs.copy()
|
||||
initkwargs.update(method_kwargs)
|
||||
url_path = initkwargs.pop("url_path", None) or methodname
|
||||
url_path = initkwargs.pop('url_path', None) or methodname
|
||||
ret.append(Route(
|
||||
url=replace_methodname(route.url, url_path),
|
||||
mapping=dict((httpmethod, methodname) for httpmethod in httpmethods),
|
||||
|
@ -254,6 +254,11 @@ class SimpleRouter(BaseRouter):
|
|||
trailing_slash=self.trailing_slash
|
||||
)
|
||||
view = viewset.as_view(mapping, **route.initkwargs)
|
||||
|
||||
# Allow dynamic routes to set `serializer_class` kwarg
|
||||
if isinstance(route, (DynamicDetailRoute, DynamicListRoute)):
|
||||
view.serializer_class = route.initkwargs.pop('serializer_class', None)
|
||||
|
||||
name = route.name.format(basename=basename)
|
||||
ret.append(url(regex, view, name=name))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user