Skip to content

Instantly share code, notes, and snippets.

@guinslym
Forked from mmartinez/check-author-mixin.py
Created July 29, 2017 08:14
Show Gist options
  • Save guinslym/ce3a2f9af35dbe0d18873a4f13e17916 to your computer and use it in GitHub Desktop.
Save guinslym/ce3a2f9af35dbe0d18873a4f13e17916 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