Skip to content

Commit e32ebc4

Browse files
authored
Docs: DjangoModelPermissions works on views with get_queryset() method. (#7693)
Sentinel querysets not needed after v3.1.2
1 parent 2345279 commit e32ebc4

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

docs/api-guide/permissions.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ This permission is suitable if you want to your API to allow read permissions to
169169

170170
## DjangoModelPermissions
171171

172-
This permission class ties into Django's standard `django.contrib.auth` [model permissions][contribauth]. This permission must only be applied to views that have a `.queryset` property set. Authorization will only be granted if the user *is authenticated* and has the *relevant model permissions* assigned.
172+
This permission class ties into Django's standard `django.contrib.auth` [model permissions][contribauth]. This permission must only be applied to views that have a `.queryset` property or `get_queryset()` method. Authorization will only be granted if the user *is authenticated* and has the *relevant model permissions* assigned.
173173

174174
* `POST` requests require the user to have the `add` permission on the model.
175175
* `PUT` and `PATCH` requests require the user to have the `change` permission on the model.
@@ -179,12 +179,6 @@ The default behaviour can also be overridden to support custom model permissions
179179

180180
To use custom model permissions, override `DjangoModelPermissions` and set the `.perms_map` property. Refer to the source code for details.
181181

182-
#### Using with views that do not include a `queryset` attribute.
183-
184-
If you're using this permission with a view that uses an overridden `get_queryset()` method there may not be a `queryset` attribute on the view. In this case we suggest also marking the view with a sentinel queryset, so that this class can determine the required permissions. For example:
185-
186-
queryset = User.objects.none() # Required for DjangoModelPermissions
187-
188182
## DjangoModelPermissionsOrAnonReadOnly
189183

190184
Similar to `DjangoModelPermissions`, but also allows unauthenticated users to have read-only access to the API.

0 commit comments

Comments
 (0)