@@ -77,7 +77,7 @@ class DjangoModelPermissions(BasePermission):
77
77
`add`/`change`/`delete` permissions on the model.
78
78
79
79
This permission can only be applied against view classes that
80
- provide a `.model` or `. queryset` attribute.
80
+ provide a `.queryset` attribute.
81
81
"""
82
82
83
83
# Map methods into required permission codes.
@@ -107,24 +107,19 @@ def get_required_permissions(self, method, model_cls):
107
107
return [perm % kwargs for perm in self .perms_map [method ]]
108
108
109
109
def has_permission (self , request , view ):
110
- # Note that `.model` attribute on views is deprecated, although we
111
- # enforce the deprecation on the view `get_serializer_class()` and
112
- # `get_queryset()` methods, rather than here.
113
- model_cls = getattr (view , 'model' , None )
114
110
queryset = getattr (view , 'queryset' , None )
115
111
116
- if model_cls is None and queryset is not None :
117
- model_cls = queryset .model
118
-
119
112
# Workaround to ensure DjangoModelPermissions are not applied
120
113
# to the root view when using DefaultRouter.
121
- if model_cls is None and getattr (view , '_ignore_model_permissions' , False ):
114
+ if queryset is None and getattr (view , '_ignore_model_permissions' , False ):
122
115
return True
123
116
124
- assert model_cls , ('Cannot apply DjangoModelPermissions on a view that'
125
- ' does not have `.model` or `.queryset` property.' )
117
+ assert queryset , (
118
+ 'Cannot apply DjangoModelPermissions on a view that '
119
+ 'does not have `.queryset` property.'
120
+ )
126
121
127
- perms = self .get_required_permissions (request .method , model_cls )
122
+ perms = self .get_required_permissions (request .method , queryset . model )
128
123
129
124
return (
130
125
request .user and
@@ -150,7 +145,7 @@ class DjangoObjectPermissions(DjangoModelPermissions):
150
145
`add`/`change`/`delete` permissions on the object using .has_perms.
151
146
152
147
This permission can only be applied against view classes that
153
- provide a `.model` or `. queryset` attribute.
148
+ provide a `.queryset` attribute.
154
149
"""
155
150
156
151
perms_map = {
@@ -171,14 +166,10 @@ def get_required_object_permissions(self, method, model_cls):
171
166
return [perm % kwargs for perm in self .perms_map [method ]]
172
167
173
168
def has_object_permission (self , request , view , obj ):
174
- model_cls = getattr (view , 'model' , None )
175
- queryset = getattr (view , 'queryset' , None )
176
-
177
- if model_cls is None and queryset is not None :
178
- model_cls = queryset .model
169
+ model_cls = view .queryset .model
170
+ user = request .user
179
171
180
172
perms = self .get_required_object_permissions (request .method , model_cls )
181
- user = request .user
182
173
183
174
if not user .has_perms (perms , obj ):
184
175
# If the user does not have permissions we need to determine if
0 commit comments