Why doesn't form_valid() in FormView take a request argument?
461 views
Skip to first unread message
Some Developer
unread,
Feb 6, 2013, 3:09:39 PM2/6/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Why doesn't the form_valid() (and for that matter the form_invalid())
method in the FormView generic class based view take a request argument?
I've found that if you have a form which requires you to override the
form_valid() method because you need to do custom logic before you save
the model and you need to save the user ID of the person who posted the
form you need to also override the post() method in order to pass on the
correct data by manually adding it to the post argument of the
form_valid() method by using request.user.
Am I missing something here? Is there any easier way to achieve what I
want to achieve?
Rainy
unread,
Feb 6, 2013, 6:00:02 PM2/6/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
How about using self.request attribute? -rainy
Some Developer
unread,
Feb 7, 2013, 3:39:43 AM2/7/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Heh I don't know how I missed that. Thanks, that solves a couple of
issues :).
I'm in the process of converting some old code to class based views and
am still getting used to using them.
Rainy
unread,
Feb 7, 2013, 6:40:46 PM2/7/13
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
No problem. There's of course also self.args and self.kwargs.
If you need to use views that inherit from multiple CBVs, take