Skip to content

Commit f744da7

Browse files
akxrpkilby
authored andcommitted
Improve the docstring on @action (#6951)
1 parent de9f1d5 commit f744da7

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

rest_framework/decorators.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,23 @@ def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
124124
"""
125125
Mark a ViewSet method as a routable action.
126126
127-
Set the `detail` boolean to determine if this action should apply to
128-
instance/detail requests or collection/list requests.
127+
`@action`-decorated functions will be endowed with a `mapping` property,
128+
a `MethodMapper` that can be used to add additional method-based behaviors
129+
on the routed action.
130+
131+
:param methods: A list of HTTP method names this action responds to.
132+
Defaults to GET only.
133+
:param detail: Required. Determines whether this action applies to
134+
instance/detail requests or collection/list requests.
135+
:param url_path: Define the URL segment for this action. Defaults to the
136+
name of the method decorated.
137+
:param url_name: Define the internal (`reverse`) URL name for this action.
138+
Defaults to the name of the method decorated with underscores
139+
replaced with dashes.
140+
:param kwargs: Additional properties to set on the view. This can be used
141+
to override viewset-level *_classes settings, equivalent to
142+
how the `@renderer_classes` etc. decorators work for function-
143+
based API views.
129144
"""
130145
methods = ['get'] if (methods is None) else methods
131146
methods = [method.lower() for method in methods]
@@ -144,6 +159,10 @@ def decorator(func):
144159
func.detail = detail
145160
func.url_path = url_path if url_path else func.__name__
146161
func.url_name = url_name if url_name else func.__name__.replace('_', '-')
162+
163+
# These kwargs will end up being passed to `ViewSet.as_view()` within
164+
# the router, which eventually delegates to Django's CBV `View`,
165+
# which assigns them as instance attributes for each request.
147166
func.kwargs = kwargs
148167

149168
# Set descriptive arguments for viewsets

0 commit comments

Comments
 (0)