Last active
July 12, 2019 18:40
-
-
Save aballah-chamakh/769c5c00818f5206b44a5f52778db893 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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