Problem with formset

48 views
Skip to first unread message

Satinderpal Singh

unread,
Oct 31, 2012, 2:30:47 PM10/31/12
to django...@googlegroups.com
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/

Lachlan Musicman

unread,
Oct 31, 2012, 3:55:25 PM10/31/12
to django...@googlegroups.com
On Thu, Nov 1, 2012 at 7:30 AM, Satinderpal Singh
<satinder...@gmail.com> wrote:
> 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()

Should that be cd.save()? Where else is cd used?


> 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...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.



--
...we look at the present day through a rear-view mirror. This is
something Marshall McLuhan said back in the Sixties, when the world
was in the grip of authentic-seeming future narratives. He said, “We
look at the present through a rear-view mirror. We march backwards
into the future.”

http://www.warrenellis.com/?p=14314

Satinderpal Singh

unread,
Nov 1, 2012, 1:32:38 AM11/1/12
to django...@googlegroups.com
On Thu, Nov 1, 2012 at 1:25 AM, Lachlan Musicman <dat...@gmail.com> wrote:
On Thu, Nov 1, 2012 at 7:30 AM, Satinderpal Singh
<satinder...@gmail.com> wrote:
> 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()

Should that be cd.save()? Where else is cd used?
No other cd is used in this view, and i did not get your above logic, cd.save() 

Lachlan Musicman

unread,
Nov 1, 2012, 4:11:02 PM11/1/12
to django...@googlegroups.com
On Thu, Nov 1, 2012 at 6:32 PM, Satinderpal Singh <satinder...@gmail.com> wrote:
On Thu, Nov 1, 2012 at 1:25 AM, Lachlan Musicman <dat...@gmail.com> wrote:
On Thu, Nov 1, 2012 at 7:30 AM, Satinderpal Singh
<satinder...@gmail.com> wrote:
> 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()

Should that be cd.save()? Where else is cd used?
No other cd is used in this view, and i did not get your above logic, cd.save() 


I think you are saying you don't understand my response? I'm asking if the problem is fixed by replacing formset.save() - with cd.save(), since you have cd = formset.cleaned_data but no other instances of cd, making it kinda useless?

should here be a cd = ObjectName() in there?


L.

Sandeep kaur

unread,
Nov 1, 2012, 11:31:47 PM11/1/12
to django...@googlegroups.com
On Fri, Nov 2, 2012 at 1:41 AM, Lachlan Musicman <dat...@gmail.com> wrote:

>
> I think you are saying you don't understand my response? I'm asking if the
> problem is fixed by replacing formset.save() - with cd.save(), since you
> have cd = formset.cleaned_data but no other instances of cd, making it kinda
> useless?
>
> should here be a cd = ObjectName() in there?
>
According to me, he need not to assign cd, because it is then not used
anywhere to clean the form data.

--
Sandeep Kaur
E-Mail: mkaur...@gmail.com
Blog: sandymadaan.wordpress.com

Satinderpal Singh

unread,
Nov 2, 2012, 1:32:10 AM11/2/12
to django...@googlegroups.com
On Fri, Nov 2, 2012 at 1:41 AM, Lachlan Musicman <dat...@gmail.com> wrote:
On Thu, Nov 1, 2012 at 6:32 PM, Satinderpal Singh <satinder...@gmail.com> wrote:
On Thu, Nov 1, 2012 at 1:25 AM, Lachlan Musicman <dat...@gmail.com> wrote:
On Thu, Nov 1, 2012 at 7:30 AM, Satinderpal Singh
<satinder...@gmail.com> wrote:
> 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()

Should that be cd.save()? Where else is cd used?
No other cd is used in this view, and i did not get your above logic, cd.save() 


I think you are saying you don't understand my response? I'm asking if the problem is fixed by replacing formset.save() - with cd.save(), since you have cd = formset.cleaned_data but no other instances of cd, making it kinda useless?
I tried this way, but it do not solve the problem.  

should here be a cd = ObjectName() in there?
If that is the case, how cd can save the data. But the problem is not with saving the entries but to clear the previous form entries. 

Lachlan Musicman

unread,
Nov 4, 2012, 3:29:39 PM11/4/12
to django...@googlegroups.com
Ok, I admit that I saw the cd and stopped thinking straight - apologies.

I don't know why you are getting the problem you are getting, but I would suggest that you should delete one indentation one the render_to_response line, so that it catches *everything* that falls through the cracks.

Also, we will probably need to see the view 'Automation.report.views.result_chem' since this view seems to be fine - and it's after a save that the issues start, correct?

cheers
L.



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