Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Improve documentation regarding serializer class on extra actions.#6410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
963607af5c3bd00f8e3ddab6d5d0File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -144,7 +144,7 @@ A more complete example of extra actions: | ||
| queryset = User.objects.all() | ||
| serializer_class = UserSerializer | ||
| @action(detail=True, methods=['post'], serializer_class=PasswordSerializer) | ||
Collaborator
| ||
| def set_password(self, request, pk=None): | ||
| user = self.get_object() | ||
| serializer = PasswordSerializer(data=request.data) | ||
| @@ -168,9 +168,9 @@ A more complete example of extra actions: | ||
| serializer = self.get_serializer(recent_users, many=True) | ||
| return Response(serializer.data) | ||
| The decorator can additionally take extra arguments that will be set for the routed view only.Any class property of the `ViewSet` is therefore a valid argument for `@action()` (e.g. `serializer_class`, `queryset`, `permission_classes`).For example, an action which sets a password needs different permissions and a different form to be displayed compared to the regular `UserViewSet`: | ||
| @action(detail=True, methods=['post'], permission_classes=[IsAdminOrIsSelf], serializer_class=PasswordSerializer) | ||
| def set_password(self, request, pk=None): | ||
| ... | ||