#4412 closed (fixed)
Allow Select and SelectMultiple widgets to render HTML optgroups from nested choices structures
Reported by: | Tai Lee | Owned by: | Chris Beaven |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | newforms select widget nested choices optgroup | |
Cc: | real.human@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | UI/UX: |
Description
if the label of a choices iterable is a list or tuple, treat that option as an option group with the value as the label.
this shouldn't break any backwards compatibility and negates the need for a separate SelectGrouped widget (which has been previously rejected).
Attachments (8)
Change History (26)
Changed 16 years ago by
Attachment: | 4412-1.diff added |
---|
comment:1 Changed 16 years ago by
Summary: | [patch] changed newforms' Select widget to accept nested choices and display using the optgroup tag. → Allow Select and SelectMultiple widgets to render HTML optgroups from nested choices structures |
---|
comment:2 Changed 16 years ago by
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 Changed 16 years ago by
Needs documentation: | set |
---|---|
Triage Stage: | Design decision needed → Accepted |
Accepted; needs documentation.
Changed 16 years ago by
Attachment: | 4412-2.diff added |
---|
comment:4 Changed 16 years ago by
Needs documentation: | unset |
---|
That reminded me that I overlooked get_FIELD_display. Done and done.
Changed 16 years ago by
updated to work on trunk, after unicode changes.
comment:5 Changed 16 years ago by
Triage Stage: | Accepted → Ready for checkin |
---|
Ready for checkin: JKM accepted, has tests, has docs, looks good.
Changed 16 years ago by
Attachment: | 4412-r6025.diff added |
---|
Update to r6025, plus some polish to docs and implementation
comment:6 Changed 16 years ago by
Owner: | changed from nobody to Matt McClanahan |
---|---|
Status: | new → assigned |
comment:7 Changed 16 years ago by
Owner: | changed from Matt McClanahan to nobody |
---|---|
Status: | assigned → new |
Er. No, I don't own this. :P
comment:8 Changed 16 years ago by
Triage Stage: | Ready for checkin → Accepted |
---|
I think "ready to checkin" is a little optimistic at this point. As Russell points out in the related django-dev thread, the patch will have problems with existing admin, so it needs to wait until after newforms-admin is merged.
comment:9 Changed 15 years ago by
milestone: | → 1.0 beta |
---|
comment:10 Changed 15 years ago by
Owner: | changed from nobody to Chris Beaven |
---|---|
Status: | new → assigned |
Note: I've got an updated version of this patch running which fixes a few issues... If i haven't put it live in a week, bug me about it.
Changed 15 years ago by
Attachment: | 4412.2.diff added |
---|
Updated patch, fixed to work with multiple select and old admin
comment:11 Changed 15 years ago by
This new patch allows this to continue with the old admin (even if it is going to be short-lived - i needed it for now) and also makes MultipleSelect
work. I abstracted some of the widget rendering logic between Select
and MultipleSelect
which also meant making MultipleSelect
a subclass of Select
, which I always thought it should have been anyway...
Added tests for the new MultipleSelect
functionality.
comment:12 Changed 15 years ago by
Amusingly, I see that Russ had already done the SelectMultiple
work. But I like my abstraction a bit better.
comment:13 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(In [7977]) Fixed #4412 -- Added support for optgroups, both in the model when defining choices, and in the form field and widgets when the optgroups are displayed. Thanks to Matt McClanahan <cardinal@…>, Tai Lee <real.human@…> and SmileyChris for their contributions at various stages in the life of this ticket.
comment:14 Changed 15 years ago by
i found a small problem when using nested choice structures:
on models.py
class Item(models.Model):
#common object properties
name = models.CharField(max_length=60)
category = models.CharField("Item Category", max_length=20, choices=ITEM_TREE)
on admin.py
class ItemAdmin(admin.ModelAdmin):
list_display = ('name', 'category',)
list_filter = ('category',)
when i browse to: /admin/item/item/
i see the choices bot most of them are python's tuples
Filter
By Item Category
All
Outer 1
(('inner1', 'Inner 1'),
('inner2', 'Inner 2'))
(screenshot: http://imagenes.zarate.net.ve/varias/djangobug.png)
comment:15 Changed 15 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:16 follow-up: 17 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Please do not reopen fixed tickets to report new problems. If there is a problem with new function added by this ticket, it should be reported in its own ticket. This also sounds vaguely familiar so do check to see if it's already been reported in an open ticket.
Also, please use preview before submitting your ticket and learn the basics of WikiFormatting so that your text will be readable.
Initial implementation proposal. An example choices structure (from the tests in the patch):
yields the following HTML: