I have this code
class ObjectCreate(CreateView):
def form_valid(self, form):
I want to know that is this form already bounded to object instance and i can use form.save or i have to bound it to model instance manually
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, the form in
form_validis bound.You can see this by looking at the code for
ProcessFormView.You can see that a bound form is instantiated by
self.get_form(form_class), and theform_validmethod is only called if the form is valid.Note that the
ModelFormMixinused by theCreateViewsaves the object by default — depending on what you are trying to do, you may not have to overrideform_valid.