Wednesday, October 31, 2012

Problem with formset

I use formset in my views.py file for the forms. It saves the entries from the form to the database but the problem is that it shows all the previous forms along with the new form for the new entry. The code for my views file is given below:

def chemical_analysis(request):
ChemicalFormSet = modelformset_factory(chem_analysis)
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'))
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))

Any help will be appreciated.  

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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment