Opened 13 years ago

Closed 13 years ago

#16467 closed Cleanup/optimization (fixed)

Little typo in the Formset docu

Reported by: hannes.hapke@… Owned by: teraom
Component: Documentation Version: 1.3
Severity: Normal Keywords: form inital value
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Is it possible that the example regarding "Using initial data with a formset" has too many brackets?

>>> formset = ArticleFormSet(initial=[
...     {'title': u'Django is now open source',
...      'pub_date': datetime.date.today()},
... ])

could it be ... (above did knot work for me)

>>> formset = ArticleFormSet(initial={
...     'title': u'Django is now open source',
...     'pub_date': datetime.date.today(),
... })

With the inital example I get the error msg:

dictionary update sequence element #0 has length 5; 2 is required

Just a thought.

Best regards,
Hannes

Attachments (1)

formset_example.diff (689 bytes ) - added by teraom 13 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Bernhard Essl, 13 years ago

Component: FormsDocumentation
Triage Stage: UnreviewedAccepted

comment:2 by teraom, 13 years ago

Owner: changed from nobody to teraom
Status: newassigned

by teraom, 13 years ago

Attachment: formset_example.diff added

comment:3 by teraom, 13 years ago

Has patch: set

comment:4 by Aymeric Augustin, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: assignedclosed

In [16564]:

Fixed #16467 -- Corrected formset code example. Thanks, teraom.

comment:6 by dmclain, 13 years ago

Resolution: fixed
Status: closedreopened

The documentation was correct as written. Initial should be an array of dictionaries where the dictionaries are used for successive forms.

If you look at https://code.djangoproject.com/browser/django/trunk/django/forms/formsets.py#L110 to construct the i'th form instance the initial paramater pulls self.initial[i]

comment:7 by Gabriel Hurley, 13 years ago

Resolution: fixed
Status: reopenedclosed

In [16623]:

Fixed #16467 -- Restored a previously correct example which was broken in [16564]. Thanks to dmclain for pointing out that the original example was correct.

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