Code

Opened 3 years ago

Closed 3 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 3 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 3 years ago by BernhardEssl

  • Component changed from Forms to Documentation
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 3 years ago by teraom

  • Owner changed from nobody to teraom
  • Status changed from new to assigned

Changed 3 years ago by teraom

comment:3 Changed 3 years ago by teraom

  • Has patch set

comment:4 Changed 3 years ago by aaugustin

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from assigned to closed

In [16564]:

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

comment:6 Changed 3 years ago by dmclain

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 Changed 3 years ago by gabrielhurley

  • Resolution set to fixed
  • Status changed from reopened to closed

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.

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.