django form valid

Solutions on MaxInterview for django form valid by the best coders in the world

showing results for - "django form valid"
Louka
18 Jul 2017
1If you save a form with commit=False, you must call the form's save_m2m method to save the many-to-many data. See the docs for more info.
2
3If you decide to use the form_valid method, I would change the following things:
4
5update the instance returned by form.save() and save it, instead of calling form.save() again.
6explicitly call form.save_m2m()
7return a redirect response instead of calling super().form_valid() (which will save the form again)
8Putting that together, you get:
9
10def form_valid(self, form):
11    product = form.save(commit=False)
12    product.user =  self.request.user
13    product.location.location = user.user_location
14    product.save()
15    form.save_m2m()
16    return redirect('/success-url/')
queries leading to this page
django model form validationhow to validate in django formsdjango form validation codeadd validators to django formshow use django model for form validationdjango if form is valid 28 29form validation in django formsvalidate form field djangodjango forms is validdjango validator in formvalidation in django formsform is valid 28 29 false djangoform is valid 28 29 djangodjango form validatorform is valid false djangoform validation django formsdjango forms form validationdjango validation formdjango forms validate fieldhow to validate forms in djangodjango form validation exampleis valid with html forms in djangovalidation in django formhow to write a form validator in djangodjango form validation modelformdjango form valid cleaned dataform validation on djangoform is valid 28 29 in djangoif form is valid djangodjango form validationdjango validate form datadjango form field validhow to use django inbuilt form validation with html formsdjango field form validatordjango formset is validhow to validate form in djangohow to validate django formform is valid djangodjango form validade fieldform validator djangodjango form is valid without modelis valid django formform validators in djangoform validators in django docsvalidate django formsetforms is valid djangodjango validate formsdjango model form field validationhow to validate forms in django formsdjango form is validdjango check if form is validforms modelform validation djangoformofis valid djangoform is valid django mathoddjango form is valid always falsehow to check if django form is validhow to validate a form in djangoform is valid djangovalidate in django formsdjango validate modelformdjango form validation tutorialhow to add valid form method in djangoform validations djangohow to validate a form djangoforms validation in djangovalidate form djangodjango form validform valid djangocreatevuew form valid djangoform validators djangoif self form valid 28 29 djangodjango form validationsdjango form is validhow to validate html form in djangodjango cusotm form validationwhat makes a form valid in djangodjango forms validationdjango validate formsetdjango validating formsis valid form djangodjango if form is validdjango form use validator tutorialdjango forms validatorsmodelform django validatewhat is validating form djangovalidate form through django formdjango form is valid examplevalidator in django model formdjango form validationvalidate form in djangoforms validation djangoform validation django examplesdef form valid 28self 2c form django 29validate html form in djangohow to write a form validator i djangoform validation djangodjango form is valid 28 29django form validdjango form validatorsvalidatios on django formsform is valid djangovalidators on django formsdjango form validatevalidation django formdjango validation in form or modelform field validation in djangodjango form field validationdjango form validation for fielddjango valid formhow to check validation in django formsdjango form validation in forms pydef form valid djangodjango validate formdjango form validaeform valid forms djangovalidate manual form in djangoform django validationform validate djangodjango forms check if validform field validation djangovalidation form djangoform valid djangodjango form is validis valid forms djangoform validation in djangovalid form in djangovalidating form in html using djangoform validation in django pythondjango form validate fieldform valid model djangocheck if form is valid djangodjango form use validatorif form is valid 28 29 djangoform validation django exampledjango form valid methoddjango how to validate formdjango form valid