-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve documentation regarding serializer class on extra actions. #6410
Improve documentation regarding serializer class on extra actions. #6410
Conversation
The documentation does currently not describe how to use a custom `serializer_class` with extra actions. The example uses a custom serializer without using the seralizer_class attribute, resulting in the generated documentation page presenting the wrong form. The author of the feature described the usage of the `serializer_class` kwarg in his pr #5605: #5605 (comment)
Hi, Thank you for the contribution. |
…ions." partially This reverts commit 963607a partially. It is just a specific example of the already documented "can take extra arguments". The fix for the example was not reverted.
I see, actually, right after the example, it says exactly that. I just didn't get it. Still, I would like to contribute the fix of the example code, passing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clarification after the example seems good.
I’m not sure about the first addition. It’s perhaps overly complex for the first example.
Maybe passing two kwargs in the second case, i.e. serializer_class as well...?
@@ -144,7 +144,7 @@ A more complete example of extra actions: | |||
queryset = User.objects.all() | |||
serializer_class = UserSerializer | |||
|
|||
@action(detail=True, methods=['post']) | |||
@action(detail=True, methods=['post'], serializer_class=PasswordSerializer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we then use self.get_serializer()
in the method body? (Otherwise the kwarg isn’t doing anything...)
(Although see main comment.)
The kwarg is necessary, regardless of usage inside the function. Without the kwarg, the generated doc will show the I feel that it might be common that extra actions have other inputs than the normal actions. Therefore I think it's a good idea to show correct usage of another serializer. |
Hi @soerface. Yes, right. I'm thinking then we should rephrase a little bit to spell that out. (Note emphasis on little.) Happy if you want have a pop at that. If not I'll give it a look over. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
The documentation does currently not describe how to use a custom
serializer_class
with extra actions. The example uses a custom serializer without using the seralizer_class attribute, resulting in the generated documentation page presenting the wrong form.The author of the feature described the usage of the
serializer_class
kwarg in his PR #5605 (comment)