Skip to content

Instantly share code, notes, and snippets.

@aballah-chamakh
Last active July 12, 2019 18:40
Show Gist options
  • Select an option

  • Save aballah-chamakh/769c5c00818f5206b44a5f52778db893 to your computer and use it in GitHub Desktop.

Select an option

Save aballah-chamakh/769c5c00818f5206b44a5f52778db893 to your computer and use it in GitHub Desktop.
from rest_framework import permissions
class IsOwnerAndAuthenticated(permissions.BasePermission):
def has_permission(self, request, view):
# let permmission just for create user
if request.method == 'POST' :
return True
return request.user.is_authenticated
def has_object_permission(self, request, view, obj):
#for the profile model
if type(obj).__name___ :
return request.user.profile == obj
# for the User model
return request.user == obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment