Skip to content

Commit 046bf8a

Browse files
author
Ryan P Kilby
committed
Add 'ViewSet.detail' initkwarg
1 parent d673622 commit 046bf8a

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

rest_framework/routers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ def get_urls(self):
284284
initkwargs = route.initkwargs.copy()
285285
initkwargs.update({
286286
'basename': basename,
287+
'detail': route.detail,
287288
})
288289

289290
view = viewset.as_view(mapping, **initkwargs)

rest_framework/viewsets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def as_view(cls, actions=None, **initkwargs):
5656
# eg. 'List' or 'Instance'.
5757
cls.suffix = None
5858

59+
# The detail initkwarg is reserved for introspecting the viewset type.
60+
cls.detail = None
61+
5962
# Setting a basename allows a view to reverse its action urls. This
6063
# value is provided by the router through the initkwargs.
6164
cls.basename = None

tests/test_routers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ def test_suffix(self):
446446

447447
assert initkwargs['suffix'] == 'List'
448448

449+
def test_detail(self):
450+
match = resolve('/example/notes/')
451+
initkwargs = match.func.initkwargs
452+
453+
assert not initkwargs['detail']
454+
449455
def test_basename(self):
450456
match = resolve('/example/notes/')
451457
initkwargs = match.func.initkwargs

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy