Created
January 24, 2012 02:23
-
-
Save sleekslush/1667396 to your computer and use it in GitHub Desktop.
Adding request user to a form save
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great explanation. Thanks.
To avoid severe brain melt, I've backed off an am doing it the "easy" way first. I'll post that when I've got it done (probably tomorrow night). Then I can circle back to try and use
CreateView
again.Even without
CreateView
, I think it's going to be pretty slim. Being able to useModelForm
andform.save(commit=False)
makes things super nice.