diff options
| author | Tom Christie | 2014-08-29 10:03:07 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-08-29 10:03:07 +0100 | 
| commit | 8f4ae06b3b3b9572d72529ffad1842f63ca67d91 (patch) | |
| tree | 2fc2c0ce267ae04e69213a810286c8b47b02826f /rest_framework | |
| parent | bb1604674f05c0fa5c62e7bb3e7b9d12fd9bf648 (diff) | |
| parent | 8b2052172cf7138203e683731c30bd279c6e722a (diff) | |
| download | django-rest-framework-8f4ae06b3b3b9572d72529ffad1842f63ca67d91.tar.bz2 | |
Merge pull request #1784 from tomchristie/remove-model-attribute
Deprecate `.model` attribute on views
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/generics.py | 11 | ||||
| -rw-r--r-- | rest_framework/permissions.py | 3 | ||||
| -rw-r--r-- | rest_framework/routers.py | 5 | 
3 files changed, 18 insertions, 1 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py index 77deb8e4..a6f68657 100644 --- a/rest_framework/generics.py +++ b/rest_framework/generics.py @@ -252,6 +252,12 @@ class GenericAPIView(views.APIView):          if serializer_class is not None:              return serializer_class +        warnings.warn( +            'The `.model` attribute on view classes is now deprecated in favor ' +            'of the more explicit `serializer_class` and `queryset` attributes.', +            DeprecationWarning, stacklevel=2 +        ) +          assert self.model is not None, \              "'%s' should either include a 'serializer_class' attribute, " \              "or use the 'model' attribute as a shortcut for " \ @@ -282,6 +288,11 @@ class GenericAPIView(views.APIView):              return self.queryset._clone()          if self.model is not None: +            warnings.warn( +                'The `.model` attribute on view classes is now deprecated in favor ' +                'of the more explicit `serializer_class` and `queryset` attributes.', +                DeprecationWarning, stacklevel=2 +            )              return self.model._default_manager.all()          error_format = "'%s' must define 'queryset' or 'model'" diff --git a/rest_framework/permissions.py b/rest_framework/permissions.py index 6a1a0077..29f60d6d 100644 --- a/rest_framework/permissions.py +++ b/rest_framework/permissions.py @@ -108,6 +108,9 @@ class DjangoModelPermissions(BasePermission):          return [perm % kwargs for perm in self.perms_map[method]]      def has_permission(self, request, view): +        # Note that `.model` attribute on views is deprecated, although we +        # enforce the deprecation on the view `get_serializer_class()` and +        # `get_queryset()` methods, rather than here.          model_cls = getattr(view, 'model', None)          queryset = getattr(view, 'queryset', None) diff --git a/rest_framework/routers.py b/rest_framework/routers.py index 406ebcf7..ae56673d 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -128,6 +128,9 @@ class SimpleRouter(BaseRouter):          If `base_name` is not specified, attempt to automatically determine          it from the viewset.          """ +        # Note that `.model` attribute on views is deprecated, although we +        # enforce the deprecation on the view `get_serializer_class()` and +        # `get_queryset()` methods, rather than here.          model_cls = getattr(viewset, 'model', None)          queryset = getattr(viewset, 'queryset', None)          if model_cls is None and queryset is not None: @@ -135,7 +138,7 @@ class SimpleRouter(BaseRouter):          assert model_cls, '`base_name` argument not specified, and could ' \              'not automatically determine the name from the viewset, as ' \ -            'it does not have a `.model` or `.queryset` attribute.' +            'it does not have a `.queryset` attribute.'          return model_cls._meta.object_name.lower()  | 
