Django

Code

Ticket #8435 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

Document formset's `prefix` argument.

Reported by: takkun Assigned to: nobody
Milestone: 1.0 Component: Documentation
Version: 1.0-alpha-2 Keywords: formsets
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by jacob)

See Brian's comment; this is a doc issue. Original report follows -- JKM

As of this moment one is able to utilize multiple formsets within a single view, as long as one does not use the same variable name for the fields in the respective forms. But this breaks down on the template level, specifically the management_form portion of formsets. The variables form-TOTAL_FORMS and form-INITIAL_FORMS are shared for all formsets when you include each formset's management_form in the template: {{ formset.management_form }}.

The problem isn't immediately apparent since the template will render correctly due to the fact that you call the management_form for each formset, thus in turn over-writing the variables form-TOTAL_FORMS and form-INITIAL_FORMS each time you do. The trouble begins when you start processing the request.POST data.

Let's say you have 2 formsets displayed in a template, the first one you configure with 4 fields and the second with 2 fields. When you then process the POST data in the view by calling "for form in formset1.forms" it will only iterate 2 times oppose to the 4 times one would initially expect, all due to the fact that formset2's management_form has now over-written the form-TOTAL_FORMS variable; thus you lose whatever data was submitted in the remaining 2 fields in formset1.

Attachments

Change History

08/19/08 21:25:49 changed by brosner

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • milestone changed from 1.0 maybe to 1.0.

This ticket is actually invalid. You need to use prefix just like a Form to allow for more than one formset to co-exist in POST data. However, this is not documented. Leaving opening for the documentation change.

08/25/08 13:31:55 changed by jacob

  • component changed from Forms to Documentation.
  • description changed.
  • summary changed from Using multiple formsets within a single template to Document formset's `prefix` argument..

08/27/08 11:45:46 changed by brosner

  • status changed from new to closed.
  • resolution set to fixed.

(In [8631]) Fixed #8435 -- Documented the prefix option on formsets.


Add/Change #8435 (Document formset's `prefix` argument.)




Change Properties
Action