aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'djangorestframework/views.py')
-rw-r--r--djangorestframework/views.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/djangorestframework/views.py b/djangorestframework/views.py
index 626dc696..545671a4 100644
--- a/djangorestframework/views.py
+++ b/djangorestframework/views.py
@@ -58,6 +58,18 @@ class BaseView(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, View):
name = None
description = None
+ @classmethod
+ def as_view(cls, **initkwargs):
+ """
+ Override the default :meth:`as_view` to store an instance of the view
+ as an attribute on the callable function. This allows us to discover
+ information about the view when we do URL reverse lookups.
+ """
+ view = super(BaseView, cls).as_view(**initkwargs)
+ view.cls_instance = cls(**initkwargs)
+ return view
+
+
@property
def allowed_methods(self):
"""
@@ -129,12 +141,12 @@ class ModelView(BaseView):
class InstanceModelView(InstanceMixin, ReadModelMixin, UpdateModelMixin, DeleteModelMixin, ModelView):
"""A view which provides default operations for read/update/delete against a model instance."""
- pass
+ _suffix = 'Instance'
class ListModelView(ListModelMixin, ModelView):
- """A view which provides default operations for list, against a model in the database."""
- pass
+ """A view which provides default operations for list, against a model in the database."""
+ _suffix = 'List'
class ListOrCreateModelView(ListModelMixin, CreateModelMixin, ModelView):
- """A view which provides default operations for list and create, against a model in the database."""
- pass
+ """A view which provides default operations for list and create, against a model in the database."""
+ _suffix = 'List'