Source

djangorators / djangorators / permissions.py

from django.http import HttpResponseNotFound

def owner_required(func):
    """
    Warning: depends on from_object's djangorator for the related_* access.
    """
    def _dec(request, *args, **kwargs):
        if 'related_object' in kwargs:
            if kwargs['related_object'].owner == request.user:
                return func(request, *args, **kwargs)
        elif 'related_queryset' in kwargs:
            kwargs['related_queryset'] = kwargs['related_queryset'].filter(owner=request.user)
            return func(request, *args, **kwargs)
        
        return HttpResponseNotFound()
    return _dec