aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/viewsets.py
diff options
context:
space:
mode:
authorTom Christie2013-05-05 16:48:00 +0100
committerTom Christie2013-05-05 16:48:00 +0100
commit660d2405174519628c72ed84a69ae37531df12f3 (patch)
tree60d2c1a1718184ab9e426e63bf7cf443459d8bba /rest_framework/viewsets.py
parent538d2e35e7f1e4623a215d1b8c684b284f951c09 (diff)
downloaddjango-rest-framework-660d2405174519628c72ed84a69ae37531df12f3.tar.bz2
.action attribute on viewsets
Diffstat (limited to 'rest_framework/viewsets.py')
-rw-r--r--rest_framework/viewsets.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/rest_framework/viewsets.py b/rest_framework/viewsets.py
index a54467d7..0eb3e86d 100644
--- a/rest_framework/viewsets.py
+++ b/rest_framework/viewsets.py
@@ -59,6 +59,10 @@ class ViewSetMixin(object):
def view(request, *args, **kwargs):
self = cls(**initkwargs)
+ # We also store the mapping of request methods to actions,
+ # so that we can later set the action attribute.
+ # eg. `self.action = 'list'` on an incoming GET request.
+ self.action_map = actions
# Bind methods to actions
# This is the bit that's different to a standard view
@@ -87,6 +91,15 @@ class ViewSetMixin(object):
view.suffix = initkwargs.get('suffix', None)
return view
+ def initialize_request(self, request, *args, **kargs):
+ """
+ Set the `.action` attribute on the view,
+ depending on the request method.
+ """
+ request = super(ViewSetMixin, self).initialize_request(request, *args, **kargs)
+ self.action = self.action_map.get(request.method.lower())
+ return request
+
class ViewSet(ViewSetMixin, views.APIView):
"""