Opened 11 years ago

Closed 10 years ago

Last modified 7 years ago

#7738 closed (fixed)

[newforms-admin] defaults for ManyToManyFields are broken on add page

Reported by: John Shaffer Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords: selectmultiple, forms, admin
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


In trunk, /app/model/add/?options=12, where options is a ManyToManyField, works as expected: the Option with a pk of 12 is selected. In newforms-admin, it is interpreted as if the querystring had been options=1,2: the Options with pks of 1 and 2 are selected.

Attachments (1)

7738.diff (542 bytes) - added by gkelly 10 years ago.
Patch for when exception is caught, f would be undefined.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 11 years ago by Sung-jin Hong

Triage Stage: UnreviewedAccepted

comment:2 Changed 10 years ago by Ivan Giuliani

milestone: 1.0

The problem described here belongs to this line:
Actually, the initial_data for model forms on SelectMultipleWidget expects an iterable object like a list or tuple for selecting the choices, while instead we're passing a string - i.e. "12" - that get then divided in in "1" and "2". I thought this could be changed in something like string.split(',') but I can see this behaviour is not documented anywhere, so maybe some core dev has a better idea (or maybe this should be marked as wontfix?).

comment:3 Changed 10 years ago by Ivan Giuliani

Keywords: selectmultiple forms admin added
Version: newforms-adminSVN

Just a note here since probably I was a bit drunk when I wrote the comment above: the widget is SelectMultiple obviously and what expects an iterable object is the choices attribute of render().

comment:4 Changed 10 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [8699]) Fixed #7738: support initial values via GET for SelectMutliple in the admin.

Changed 10 years ago by gkelly

Attachment: 7738.diff added

Patch for when exception is caught, f would be undefined.

comment:5 Changed 10 years ago by gkelly

Undefined f fixed in [8714]

comment:6 Changed 7 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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