Add 'ViewSet.detail' initkwarg

This commit is contained in:
Ryan P Kilby 2017-12-22 03:51:37 -05:00
parent 034f8d0283
commit fed7616013
3 changed files with 10 additions and 0 deletions

View File

@ -284,6 +284,7 @@ class SimpleRouter(BaseRouter):
initkwargs = route.initkwargs.copy() initkwargs = route.initkwargs.copy()
initkwargs.update({ initkwargs.update({
'basename': basename, 'basename': basename,
'detail': route.detail,
}) })
view = viewset.as_view(mapping, **initkwargs) view = viewset.as_view(mapping, **initkwargs)

View File

@ -56,6 +56,9 @@ class ViewSetMixin(object):
# eg. 'List' or 'Instance'. # eg. 'List' or 'Instance'.
cls.suffix = None cls.suffix = None
# The detail initkwarg is reserved for introspecting the viewset type.
cls.detail = None
# Setting a basename allows a view to reverse its action urls. This # Setting a basename allows a view to reverse its action urls. This
# value is provided by the router through the initkwargs. # value is provided by the router through the initkwargs.
cls.basename = None cls.basename = None

View File

@ -446,6 +446,12 @@ class TestViewInitkwargs(TestCase):
assert initkwargs['suffix'] == 'List' assert initkwargs['suffix'] == 'List'
def test_detail(self):
match = resolve('/example/notes/')
initkwargs = match.func.initkwargs
assert not initkwargs['detail']
def test_basename(self): def test_basename(self):
match = resolve('/example/notes/') match = resolve('/example/notes/')
initkwargs = match.func.initkwargs initkwargs = match.func.initkwargs