Skip to content

Commit ba7e3fc

Browse files
author
Ryan P Kilby
committed
Router sets 'detail' & 'basename' on ViewSet
1 parent 8a054f5 commit ba7e3fc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

rest_framework/routers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,13 @@ def get_urls(self):
293293
if not prefix and regex[:2] == '^/':
294294
regex = '^' + regex[2:]
295295

296-
view = viewset.as_view(mapping, **route.initkwargs)
296+
initkwargs = route.initkwargs.copy()
297+
initkwargs.update({
298+
'basename': basename,
299+
'detail': route.detail,
300+
})
301+
302+
view = viewset.as_view(mapping, **initkwargs)
297303
name = route.name.format(basename=basename)
298304
ret.append(url(regex, view, name=name))
299305

rest_framework/viewsets.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,17 @@ def as_view(cls, actions=None, **initkwargs):
4747
instantiated view, we need to totally reimplement `.as_view`,
4848
and slightly modify the view function that is created and returned.
4949
"""
50-
# The suffix initkwarg is reserved for identifying the viewset type
50+
# The suffix initkwarg is reserved for displaying the viewset type.
5151
# eg. 'List' or 'Instance'.
5252
cls.suffix = None
5353

54+
# The detail initkwarg is reserved for introspecting the viewset type.
55+
cls.detail = None
56+
57+
# Setting a basename allows a view to reverse its action urls. This
58+
# value is provided by the router through the initkwargs.
59+
cls.basename = None
60+
5461
# actions must not be empty
5562
if not actions:
5663
raise TypeError("The `actions` argument must be provided when "

0 commit comments

Comments
 (0)