Opened 5 years ago

Last modified 5 years ago

#30998 closed New feature

Make it easier to use the model instance in ChoiceWidget.create_option() — at Version 2

Reported by: Jon Dufresne Owned by: nobody
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 (2)

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.

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