#30998: Make it easier to use the model instance in ChoiceWidget.create_option()
------------------------------+------------------------------------
Reporter: Jon Dufresne | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Carlton Gibson):
* needs_docs: 0 => 1
* stage: Unreviewed => Accepted
Old description:
> 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.
New description:
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.
--
Comment:
Hi Jon. Yes, super.
([https://github.com/carltongibson/django-
filter/blob/9a11b0bb8c3aaf8275b586458ec7acffcaaea104/django_filters/fields.py#L214-L275
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30998#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.9366a31f1e8ee5268f39d4ed9871abb2%40djangoproject.com.