mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-09-17 01:32:30 +03:00
Updated documentation and simplified code
This commit is contained in:
parent
ecae64fe9a
commit
6d4d048ed5
|
@ -173,11 +173,12 @@ This permission is suitable if you want to your API to allow read permissions to
|
|||
|
||||
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. The appropriate model is determined by checking `get_queryset().model` or `queryset.model`.
|
||||
|
||||
* `GET` requests require the user to have the `view` or `change` permission on the model
|
||||
* `POST` requests require the user to have the `add` permission on the model.
|
||||
* `PUT` and `PATCH` requests require the user to have the `change` permission on the model.
|
||||
* `DELETE` requests require the user to have the `delete` permission on the model.
|
||||
|
||||
The default behavior can also be overridden to support custom model permissions. For example, you might want to include a `view` model permission for `GET` requests.
|
||||
The default behaviour can also be overridden to support custom model permissions.
|
||||
|
||||
To use custom model permissions, override `DjangoModelPermissions` and set the `.perms_map` property. Refer to the source code for details.
|
||||
|
||||
|
|
|
@ -243,10 +243,7 @@ class DjangoModelPermissions(BasePermission):
|
|||
|
||||
user = request.user
|
||||
if request.method == 'GET':
|
||||
if user.has_perms(perms) or user.has_perms(change_perm):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return user.has_perms(perms) or user.has_perms(change_perm)
|
||||
|
||||
return user.has_perms(perms)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user