Opened 7 years ago

Closed 6 years ago

#9954 closed (duplicate)

admin change list: list_filter section breaks when using named groups in the choices field option

Reported by: ramiro Owned by: ramiro
Component: contrib.admin Version: master
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: UI/UX:

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:

http://imagenes.zarate.net.ve/varias/djangobug.png

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)

t9954-r9698.diff (3.1 KB) - added by ramiro 7 years ago.

Download all attachments as: .zip

Change History (11)

Changed 7 years ago by ramiro

comment:1 Changed 7 years ago by ramiro

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by SantiagoZarate

thanks ramiro... should i patch my django install?... or wait until it's status is accepted?

comment:3 follow-ups: Changed 7 years ago by SantiagoZarate

  • Owner changed from ramiro to SantiagoZarate
  • Status changed from new to 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

#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 in reply to: ↑ 3 Changed 7 years ago by mattmcc

Replying to SantiagoZarate:

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 in reply to: ↑ 3 Changed 7 years ago by ramiro

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?.

comment:6 follow-up: Changed 7 years ago by 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

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:7 Changed 7 years ago by ramiro

I marked #9949 as duplicate of this.

comment:8 in reply to: ↑ 6 Changed 7 years ago by ramiro

  • 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 Changed 6 years ago by ramiro

  • Owner changed from SantiagoZarate to ramiro
  • Status changed from assigned to new

comment:10 Changed 6 years ago by ramiro

  • Resolution set to duplicate
  • Status changed from new to 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 with flatchoices at two different spots in django/contrib/admin/options.py) and
  • the regression tests added for both tickets use the same model/fixtures so the hunks for the tests overlap.
Note: See TracTickets for help on using tickets.
Back to Top