Opened 16 years ago
Closed 16 years ago
#9954 closed (duplicate)
admin change list: list_filter section breaks when using named groups in the choices field option
Reported by: | Ramiro Morales | Owned by: | Ramiro Morales |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | list_filter choices nested option gropus named tuples | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
An user tried to reopen #4412 reporting this with the following (fixed) example:
#models.py from django.db import models ITEM_TREE = ( ('Outer 1', ( ('inner1', 'Inner 1'), ('inner2', 'Inner 2'), ) ), ) class Item(models.Model): name = models.CharField(max_length=60) category = models.CharField("Item Category", max_length=20, choices=ITEM_TREE)
# admin.py from t9954.models import Item from django.contrib import admin class ItemAdmin(admin.ModelAdmin): list_display = ('name', 'category',) list_filter = ('category',) admin.site.register(Item, ItemAdmin)
when going to /admin/t9954/item/ the filter section shows:
I've already fixed this and I'm working on adding a test to the model_views regression tests, will post a patch soon.
Attachments (1)
Change History (11)
by , 16 years ago
Attachment: | t9954-r9698.diff added |
---|
comment:1 by , 16 years ago
Has patch: | set |
---|
comment:2 by , 16 years ago
follow-ups: 4 5 comment:3 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
I patched my filterspecs.py ... it works fine on the filter... but now came with few new problems:
- There's no hierarchy level on the filter
- It saves the selected value (even if it is nested at some point) but doesnt shows the correct values on the item list
http://imagenes.zarate.net.ve/django/9955-no-hierarchy-no-category-names.png
- It doesn't supports more than two levels (at third it saves the third's name "nested" in the following example) and in the select box on the interface it shows this: http://imagenes.zarate.net.ve/django/9954-nested-choices-wont-work.png
#having: #models.py from django.db import models ITEM_TREE = ( ('Outer 1', ( ('inner1', 'Inner 1'), ('inner2', 'Inner 2'), ('nested', ( ('a', 'This is nested'), ('b', 'way down')) ))), ('Testing', 'net'), ) class Item(models.Model): name = models.CharField(max_length=60) category = models.CharField("Item Category", max_length=20, choices=ITEM_TREE)
sorry if i'm putting some extra stuff here... there is a ticket:9949 ticket already but its a different problem than this one....
comment:4 by , 16 years ago
Replying to SantiagoZarate:
- It doesn't supports more than two levels (at third it saves the third's name "nested" in the following example) and in the select box on the interface it shows this: http://imagenes.zarate.net.ve/django/9954-nested-choices-wont-work.png
This is by design, largely due to the limitations of HTML's optgroup element. http://www.w3.org/TR/html4/interact/forms.html#edef-OPTGROUP
comment:5 by , 16 years ago
Replying to SantiagoZarate:
- There's no hierarchy level on the filter
As per http://docs.djangoproject.com/en/dev/ref/models/fields/#choices there is not any promise that multiple-level choices
gets represented in the filter UI, if you need something like that try proposing it in the django-dev mailing list or opening another ticket because that would be a enhancemente proposal and this ticket is about a bug fix.
- It saves the selected value (even if it is nested at some point) but doesn't shows the correct values on the item list
http://imagenes.zarate.net.ve/django/9955-no-hierarchy-no-category-names.png
I don quite understand you here. The instances you see with their "Item Category" column set to None
are the ones from the third level of nesting? do you see something different in an unpatched copy of Django?.
follow-up: 8 comment:6 by , 16 years ago
Replying to ramiro:
- It saves the selected value (even if it is nested at some point) but doesn't shows the correct values on the item list
http://imagenes.zarate.net.ve/django/9955-no-hierarchy-no-category-names.png
I don quite understand you here. The instances you see with their "Item Category" column set to
None
are the ones from the third level of nesting? do you see something different in an unpatched copy of Django?.
either patched or not, i see None (when its a second level of nesting) only level working seems to be the first one...
about the proposal... is not something i _really_ need but if django supports this in the select boxes would be great to have it represented everywhere...
comment:8 by , 16 years ago
Keywords: | list_filter added; liste_filter removed |
---|
Replying to SantiagoZarate:
Replying to ramiro:
- It saves the selected value (even if it is nested at some point) but doesn't shows the correct values on the item list
http://imagenes.zarate.net.ve/django/9955-no-hierarchy-no-category-names.png
The instances you see with their "Item Category" column set to
None
are the ones from the third level of nesting? do you see something different in an unpatched copy of Django?.
either patched or not, i see None (when its a second level of nesting) only level working seems to be the first one...
This is another bug, I've opened #9969 for it. Thanks.
comment:9 by , 16 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:10 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Rather than update the patch to current trunk status I will close this as a duplicate of #9969 and will generalize the description and extend the patch there to also fix this problem.
Rationale for this is that
- both bugs are related to the same feature (using named groups in the
choices
model field option) - both are solved similarly (replacing
choices
withflatchoices
at two different spots indjango/contrib/admin/options.py
) and - the regression tests added for both tickets use the same model/fixtures so the hunks for the tests overlap.
thanks ramiro... should i patch my django install?... or wait until it's status is accepted?