Closed
Description
When turning on PAGINATE_BY in settings Adding Pagination
REST_FRAMEWORK = {
'PAGINATE_BY': 10
}
The custom permissions Object Level Permissions
from rest_framework import permissions
class IsOwnerOrReadOnly(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
"""
def has_object_permission(self, request, view, obj):
# Read permissions are allowed to any request,
# so we'll always allow GET, HEAD, or OPTIONS requests.
if request.method in permissions.SAFE_METHODS:
return True
print(obj)
# Write permissions are only allowed to the owner of the snippet.
return obj.owner == request.user
break when trying to view the list of Snippets with the following error:
AttributeError at /snippets/
'Page' object has no attribute 'owner'
Request Method: GET
Request URL: http://127.0.0.1:8000/snippets/
Django Version: 1.7.1
Exception Type: AttributeError
Exception Value:
'Page' object has no attribute 'owner'
Exception Location: /Development/Python/django/snippets_tutorial/snippets/permissions.py in has_object_permission, line 14
When disabling the PAGINATE_BY setting you are able to view the Snippets list without any error.