Opened 7 years ago

Closed 7 years ago

Last modified 4 years ago

#7738 closed (fixed)

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

Reported by: jshaffer 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: UI/UX:


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

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by serialx

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

comment:2 Changed 7 years ago by kratorius

  • milestone set to 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 7 years ago by kratorius

  • Keywords selectmultiple forms admin added
  • Version changed from newforms-admin to SVN

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 7 years ago by jacob

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

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

Changed 7 years ago by gkelly

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

comment:5 Changed 7 years ago by gkelly

Undefined f fixed in [8714]

comment:6 Changed 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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