Skip to content
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

Closed
tomchristie opened this issue May 15, 2015 · 6 comments
Closed

Document view.action #2941

tomchristie opened this issue May 15, 2015 · 6 comments

Comments

@tomchristie
Copy link
Member

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/

@nryoung
Copy link
Contributor

nryoung commented May 21, 2015

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.

@kevin-brown
Copy link
Member

I believe @tomchristie is referring to the parameter set on viewsets that is from mapping the request method to the view method (the "action").

@tomchristie
Copy link
Member Author

Correct.

@nryoung
Copy link
Contributor

nryoung commented Jun 19, 2015

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?

@dbkaplan
Copy link
Contributor

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.

@kevin-brown
Copy link
Member

Unless someone can provide a illuminating example?

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 request.method.

carltongibson added a commit to carltongibson/django-rest-framework that referenced this issue Dec 19, 2017
Closes encode#2941

Provides example of adjusting permission by action.
carltongibson added a commit that referenced this issue Dec 19, 2017
Closes #2941

Provides example of adjusting permission by action.
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this issue Nov 17, 2020
Closes encode#2941

Provides example of adjusting permission by action.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants