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
Document view.action #2941
Comments
Hey @tomchristie, are you talking about what goes on here: https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/viewsets.py#L67 ? If not, can you point me to the functionality that you are referring to? I am willing to take this one on. |
I believe @tomchristie is referring to the parameter set on viewsets that is from mapping the request method to the view method (the "action"). |
Correct. |
As, I don't really understand the full extent of how that would be used, perhaps I will let somebody else handle this. Unless someone can provide a illuminating example? |
I use view.action to determine what type of permission logic to apply. For example I have an invoice model. I have standard action for create and permission logic that checks who can create an invoice. I also have a standard update action and an additional custom action for "submit_invoice". Both update and "submit_invoice" are ways to update an invoice, but have different permission sets that need to be checked for who can do each of these actions. I am overriding has_permissions and has_object_permissions. view.action is the way I can fork my permission checking logic, because it tells me which action I am currently in. |
As mentioned above, this is largely used in permissions to differentiate between requests to different methods on viewsets, as you can't just rely on |
Closes encode#2941 Provides example of adjusting permission by action.
Closes #2941 Provides example of adjusting permission by action.
Closes encode#2941 Provides example of adjusting permission by action.
The view.action property on viewsets is useful for introducing dynamic behavior (eg modify serializer class depending on the action being invoked.)
It should be documented on the ViewSets page with an example of it's usage... http://www.django-rest-framework.org/api-guide/viewsets/
The text was updated successfully, but these errors were encountered: