'FormSet' object has no attribute 'save'

1,889 views
Skip to first unread message

Satinderpal Singh

unread,
Oct 17, 2012, 2:06:43 AM10/17/12
to django...@googlegroups.com
I used formsets for different forms in my project, it displays the
forms to user but on submitting the form it gives the following error:
'chem_analysisFormFormSet' object has no attribute 'save'. I don't
know how to save the formset in the views. Here is the code of my
views file of my project:

def chemical_analysis(request):
ChemicalFormSet = formset_factory(chem_analysisForm)
if request.method=='POST':
formset = ChemicalFormSet(request.POST, request.FILES)
if formset.is_valid():
cd = formset.cleaned_data
formset.save()
return HttpResponseRedirect(reverse('Automation.report.views.result_chem'))
#return render_to_response('report/chemical_analysis.html',
{'chem': chem,},context_instance=RequestContext(request))
else:
return HttpResponse("There was an error with your
submission. Please try again.")

else:
formset = ChemicalFormSet()
return render_to_response('report/report_add_row.html', {'formset':
formset}, context_instance=RequestContext(request))

--
Satinderpal Singh
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.in/

Tom Evans

unread,
Oct 17, 2012, 7:19:20 AM10/17/12
to django...@googlegroups.com
Why would it have a save() method? Only model forms and model formsets
have save() methods. Model formsets are defined using the
modelformset_factory factory, not formset_factory.

https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/#model-formsets

Cheers

Tom

Satinderpal Singh

unread,
Oct 17, 2012, 2:30:40 PM10/17/12
to django...@googlegroups.com
Thanks, now i clearly understand my mistake and with your help i am
able to run the program successfully.
Reply all
Reply to author
Forward
0 new messages