more formset adventures

165 views
Skip to first unread message

Michael Stevens

unread,
Jul 10, 2009, 11:30:04 AM7/10/09
to django...@googlegroups.com
Hi.

I'm using a ModelFormset created with lineformset_factory.

When I click delete on one of the records and save the formset, it
successfully removes the associated db record, but if I redisplay the
formset after the save, it's still showing the now removed form.

I've modified my code to recreate the formset from the db immediately
after the save:

if foo_formset.is_valid():
foo_formset.save()
foo_formset = FooInlineFormset(instance=bar, prefix='foo')

and it does what I expect, but shouldn't it be in the right state
after the save?

Looking at the code I think the problem is that BaseModelFormSet
doesn't do anything with deleted forms after it deletes the underlying
model object - I'm expecting them to be removed from the formset as
well.

I'm running a svn checkout of 1.1.

Is this a bug, or are my expectations dodgy? :)

Michael

Karen Tracey

unread,
Jul 10, 2009, 12:38:33 PM7/10/09
to django...@googlegroups.com

The usual pattern for form handling (http://docs.djangoproject.com/en/dev/topics/forms/#using-a-form-in-a-view) uses an HttpRedirect at the end of the is_valid() leg of handling POST data.  So generally when you have successfully performed some action requested in a form, you are not expected to be re-displaying the form that triggered that action.  Thus I think your expectations are off.  Doing work to make the form "correctly" re-display after a .save() would be a waste of cycles in the normal case.

This pattern is not Django-specific.  It is a general web application pattern that avoids duplicate POSTs resulting form a user reloading a page and confusing alert boxes when a user tried to reload a page resulting from a POST.

Karen
Reply all
Reply to author
Forward
0 new messages