Skip to content

Instantly share code, notes, and snippets.

@ddemid
Created April 1, 2014 12:00
Show Gist options
  • Save ddemid/9912555 to your computer and use it in GitHub Desktop.
Save ddemid/9912555 to your computer and use it in GitHub Desktop.
class CreateWithUserMixin(object):
def create(self, request, *args, **kwargs):
if request.DATA.get('user') is None:
request.DATA['user'] = request.user.pk
if request.DATA.get('last_changed_by') is None:
request.DATA['last_changed_by'] = request.user.pk
return super(CreateWithUserMixin, self).create(request, *args, **kwargs)
class UpdateWithUserMixin(object):
def update(self, request, *args, **kwargs):
if request.DATA.get('last_changed_by') is None:
request.DATA['last_changed_by'] = request.user.pk
return super(UpdateWithUserMixin, self).update(request, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment