Skip to content

Commit 95f0b08

Browse files
Documentation: improve the action decorator documentation (encode#7316) (encode#7380)
* Documentation: improve the action decorator documentation (encode#7316)
1 parent 0bdd537 commit 95f0b08

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

docs/api-guide/viewsets.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,21 @@ A more complete example of extra actions:
171171
serializer = self.get_serializer(recent_users, many=True)
172172
return Response(serializer.data)
173173

174-
The decorator can additionally take extra arguments that will be set for the routed view only. For example:
175-
176-
@action(detail=True, methods=['post'], permission_classes=[IsAdminOrIsSelf])
177-
def set_password(self, request, pk=None):
178-
...
179174

180175
The `action` decorator will route `GET` requests by default, but may also accept other HTTP methods by setting the `methods` argument. For example:
181176

182177
@action(detail=True, methods=['post', 'delete'])
183178
def unset_password(self, request, pk=None):
184179
...
185180

186-
The two new actions will then be available at the urls `^users/{pk}/set_password/$` and `^users/{pk}/unset_password/$`
181+
182+
The decorator allows you to override any viewset-level configuration such as `permission_classes`, `serializer_class`, `filter_backends`...:
183+
184+
@action(detail=True, methods=['post'], permission_classes=[IsAdminOrIsSelf])
185+
def set_password(self, request, pk=None):
186+
...
187+
188+
The two new actions will then be available at the urls `^users/{pk}/set_password/$` and `^users/{pk}/unset_password/$`. Use the `url_path` and `url_name` parameters to change the URL segement and the reverse URL name of the action.
187189

188190
To view all extra actions, call the `.get_extra_actions()` method.
189191

0 commit comments

Comments
 (0)