Opened 16 years ago

Closed 16 years ago

Last modified 12 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: dev
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

Description

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 16 years ago.
Patch for when exception is caught, f would be undefined.

Download all attachments as: .zip

Change History (7)

comment:1 by Sung-jin Hong, 16 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Ivan Giuliani, 16 years ago

milestone: 1.0

The problem described here belongs to this line: http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/options.py#L501
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 by Ivan Giuliani, 16 years ago

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 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

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

by gkelly, 16 years ago

Attachment: 7738.diff added

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

comment:5 by gkelly, 16 years ago

Undefined f fixed in [8714]

comment:6 by Jacob, 12 years ago

milestone: 1.0

Milestone 1.0 deleted

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