Opened 13 years ago

Closed 13 years ago

#17079 closed Uncategorized (invalid)

"extra" parameter does not add any extra lines in inline formset with initial data

Reported by: mardy@… Owned by: nobody
Component: Uncategorized Version: 1.3
Severity: Normal Keywords: formset extra
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have an inline formset, created with inlineformset_factory with extra=1. When editing the form, I always want to have one empty form in case the user wants to add a row.
My code looks like this:


        DSAFormSet = inlineformset_factory(Image, DSA, extra=1)
        if request.method == 'POST':
            dsa_formset = DSAFormSet(request.POST, instance=image, prefix='dsa')
            if dsa_formset.is_valid():
                dsa_formset.save()
        else:
            dsa_formset = DSAFormSet(instance=image, prefix='dsa')

The first time the page is loaded, we hit the "else" branch, and everything works fine: we get one extra blank form. But when the user fills it and resubmits the formset, no extra row is added.

Change History (1)

comment:1 by Claude Paroz, 13 years ago

Resolution: invalid
Status: newclosed

When you create the formset in the POST section, the extra form is created but is then filled with the POST data. You should then recreate a new formset or, better, redirect to the same view (POST should always redirect, see http://en.wikipedia.org/wiki/Post/Redirect/Get).

Note: See TracTickets for help on using tickets.
Back to Top