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:

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 Morales 16 years ago.

Download all attachments as: .zip

Change History (11)

by Ramiro Morales, 16 years ago

Attachment: t9954-r9698.diff added

comment:1 by Ramiro Morales, 16 years ago

Has patch: set

comment:2 by Santiago Zarate, 16 years ago

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

comment:3 by Santiago Zarate, 16 years ago

Owner: changed from Ramiro Morales to Santiago Zarate
Status: newassigned

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

in reply to:  3 comment:4 by Matt McClanahan, 16 years ago

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

in reply to:  3 comment:5 by Ramiro Morales, 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?.

comment:6 by Santiago Zarate, 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:7 by Ramiro Morales, 16 years ago

I marked #9949 as duplicate of this.

in reply to:  6 comment:8 by Ramiro Morales, 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 Ramiro Morales, 16 years ago

Owner: changed from Santiago Zarate to Ramiro Morales
Status: assignednew

comment:10 by Ramiro Morales, 16 years ago

Resolution: duplicate
Status: newclosed

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