Skip to content

Instantly share code, notes, and snippets.

@sleekslush
Created January 24, 2012 02:23
Show Gist options
  • Save sleekslush/1667396 to your computer and use it in GitHub Desktop.
Save sleekslush/1667396 to your computer and use it in GitHub Desktop.
Adding request user to a form save
class MyView(CreateView):
model = Team
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.user = self.request.user
self.object.save()
return FormMixin.form_valid(self, form)
@dnoyes
Copy link

dnoyes commented Jan 25, 2012

Here's what I ended up with: https://gist.github.com/1674741

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment