Code

Opened 2 years ago

Closed 2 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.

Attachments (0)

Change History (1)

comment:1 Changed 2 years ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.