On Fri, Jul 10, 2009 at 7:30 AM, Michael Stevens <mpsteven...@gmail.com>wrote:

>
> 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? :)
>

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

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to