Skip to content

Instantly share code, notes, and snippets.

@Kobold
Created April 17, 2015 08:24
Show Gist options
  • Save Kobold/c5ead2b72b2be03eb0ca to your computer and use it in GitHub Desktop.
Save Kobold/c5ead2b72b2be03eb0ca to your computer and use it in GitHub Desktop.

Revisions

  1. Kobold created this gist Apr 17, 2015.
    12 changes: 12 additions & 0 deletions permissions.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    from rest_framework import permissions


    class IsOwner(permissions.BasePermission):
    """
    Custom permission to only allow owners of an object to edit it.
    """
    def has_permission(self, request, view):
    return request.user and request.user.is_authenticated()

    def has_object_permission(self, request, view, obj):
    return obj.user == request.user