Skip to content

Instantly share code, notes, and snippets.

@mmartinez
Created March 28, 2016 22:23
Show Gist options
  • Save mmartinez/5bf02e6d2105bedd3b93 to your computer and use it in GitHub Desktop.
Save mmartinez/5bf02e6d2105bedd3b93 to your computer and use it in GitHub Desktop.
This mixin checks if the object being updated belongs to the current user.
# -*- coding: utf-8 -*-
from django.http.response import HttpResponseForbidden
class AuthorRequiredMixin(object):
def dispatch(self, request, *args, **kwargs):
obj = self.get_object()
if obj.user != self.request.user:
return HttpResponseForbidden()
return super(AuthorRequiredMixin, self).dispatch(request, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment