Opened 5 years ago

Closed 5 years ago

#30998 closed New feature (fixed)

Make it easier to use the model instance in ChoiceWidget.create_option()

Reported by: Jon Dufresne Owned by: Jon Dufresne
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Carlton Gibson)

I often find myself needing to add extra attributes to subwdiget HTML elements that depend on the model instance object. For example, HTML data-* attributes.

Others have had similar needs and created their own solutions. For example: <http://srcmvn.com/blog/2013/01/15/django-advanced-model-choice-field/>.

As this isn't built-in, there have been some backward incompatible changes on some releases: #27758.

This ticket proposes to make this feature built-in to remove the need for third party applications to copy this boilerplate.

---

Right now, the ModelChoiceField.iterator and ModelChoiceIterator aren't documented. We could take this opportunity to do so if desired.

Change History (9)

comment:2 by Carlton Gibson, 5 years ago

Description: modified (diff)
Needs documentation: set
Triage Stage: UnreviewedAccepted

Hi Jon. Yes, super.

(We have this exact kind of thing in Django Filter.) I think it should be a documented pattern. The data-* attribute is a nice example.

comment:3 by Jon Dufresne, 5 years ago

Needs documentation: unset

Sounds good. I've documented the attribute and classes.

comment:4 by Carlton Gibson, 5 years ago

Needs documentation: set

comment:5 by Jon Dufresne, 5 years ago

Needs documentation: unset

comment:6 by Carlton Gibson, 5 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Mariusz Felisiak, 5 years ago

Owner: changed from nobody to Jon Dufresne
Status: newassigned
Triage Stage: Ready for checkinAccepted

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

In 5da85ea7:

Refs #30998 -- Doc'd ModelChoiceField/ModelMultipleChoiceField.iterator attributes and ModelChoiceIterator.

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 67ea35df:

Fixed #30998 -- Added ModelChoiceIteratorValue to pass the model instance to ChoiceWidget.create_option().

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