forms - django ValidationError: u'ManagementForm data is missing or has been tampered with' -



forms - django ValidationError: u'ManagementForm data is missing or has been tampered with' -

its gonna eat mind. have created formset :

timingformset = modelformset_factory(timing, form=timingform, extra=2)

i have view :

class hospitaldoctoraddview(createview): template_name = "hospital_doctor_add.html" form_class = hospitaldoctorinfoform model = hospitaldoctor success_url = "/hospital-profile/" def get_context_data(self, **kwargs): context = super(hospitaldoctoraddview, self).get_context_data(**kwargs) context['formset'] = timingformset homecoming context def post(self, request, *args, **kwargs): form = self.form_class(request.post) print "hellooww" formset = timingformset(request.post, prefix='timings') print "wow" if form.is_valid() , formset.is_valid(): print "this" self.form_save(form) self.formset_save(formset) homecoming render(request, self.template_name, { 'form': hospitaldoctorinfoform, 'formset': formset}) def form_save(self, form): info = hospitaldoctor() info.hospital = self.request.user info.full_name = form.cleaned_data['full_name'] info.expertization = form.cleaned_data['expertization'] info.nmc_no = form.cleaned_data['nmc_no'] info.save() def formset_save(self, form): frm = timing() frm.day = form.cleaned_data['day'] frm.mng_start = form.cleaned_data['mng_start'] frm.mng_end = form.cleaned_data['mng_end'] frm.eve_start = form.cleaned_data['eve_start'] frm.eve_end = form.cleaned_data['eve_end'] frm.save()

now in template:

<form method="post" action="">{% csrf_token %} {{form}} {{formset.management_form}} <table> {% form in formset %} {{form}} {% endfor %} </table>

when displays both form. when seek save or create throws validationerror: u'managementform info missing or has been tampered with'.

i dont know whats wrong. need help...

class hospitaldoctoraddview(createview): template_name = "hospital_doctor_add.html" form_class = hospitaldoctorinfoform model = hospitaldoctor success_url = "/hospital-profile/" # improve override get_success_url below , remove def get_success_url(self): homecoming reverse('app_name_namespace:url_name') # app_name_namespace in project.urls , url_name in app.urls def get_context_data(self, **kwargs): context = super(hospitaldoctoraddview, self).get_context_data(**kwargs) context['formset'] = timingformset() homecoming context def post(self, request, *args, **kwargs): form = self.form_class(request.post) formset = timingformset(request.post, request.files) if form.is_valid() , formset.is_valid(): homecoming self.form_valid(form, formset) else: homecoming self.form_invalid(form, formset) def form_valid(self, form, formset): form.save() formset.save() homecoming httpresponseredirect(self.get_success_url()) def form_invalid(self, form, formset): homecoming self.render_to_response( self.get_context_data( form=form, formset=formset, ) )

template:

<form method="post" action="">{% csrf_token %} {{form.as_table}} <table> {{ formset }} </table> </form>

django forms formset

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -