mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-21 14:05:16 +03:00
Merge pull request #1050 from filipeximenes/master
Improving documentation about object level permissions #1049
This commit is contained in:
commit
d900847d98
|
@ -113,7 +113,10 @@ For example:
|
||||||
filter = {}
|
filter = {}
|
||||||
for field in self.multiple_lookup_fields:
|
for field in self.multiple_lookup_fields:
|
||||||
filter[field] = self.kwargs[field]
|
filter[field] = self.kwargs[field]
|
||||||
return get_object_or_404(queryset, **filter)
|
|
||||||
|
obj = get_object_or_404(queryset, **filter)
|
||||||
|
self.check_object_permissions(self.request, obj)
|
||||||
|
return obj
|
||||||
|
|
||||||
#### `get_serializer_class(self)`
|
#### `get_serializer_class(self)`
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,13 @@ If you're writing your own views and want to enforce object level permissions,
|
||||||
you'll need to explicitly call the `.check_object_permissions(request, obj)` method on the view at the point at which you've retrieved the object.
|
you'll need to explicitly call the `.check_object_permissions(request, obj)` method on the view at the point at which you've retrieved the object.
|
||||||
This will either raise a `PermissionDenied` or `NotAuthenticated` exception, or simply return if the view has the appropriate permissions.
|
This will either raise a `PermissionDenied` or `NotAuthenticated` exception, or simply return if the view has the appropriate permissions.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
def get_object(self):
|
||||||
|
obj = get_object_or_404(self.get_queryset())
|
||||||
|
self.check_object_permissions(self.request, obj)
|
||||||
|
return obj
|
||||||
|
|
||||||
## Setting the permission policy
|
## Setting the permission policy
|
||||||
|
|
||||||
The default permission policy may be set globally, using the `DEFAULT_PERMISSION_CLASSES` setting. For example.
|
The default permission policy may be set globally, using the `DEFAULT_PERMISSION_CLASSES` setting. For example.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user