Django

Code

Ticket #9954 (closed: duplicate)

Opened 6 months ago

Last modified 4 months ago

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

Reported by: ramiro Assigned to: ramiro
Milestone: Component: django.contrib.admin
Version: SVN Keywords: list_filter choices nested option gropus named tuples
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

t9954-r9698.diff (3.1 kB) - added by ramiro on 01/04/09 11:35:30.

Change History

01/04/09 11:35:30 changed by ramiro

  • attachment t9954-r9698.diff added.

01/04/09 11:35:50 changed by ramiro

  • needs_better_patch changed.
  • has_patch set to 1.
  • needs_tests changed.
  • needs_docs changed.

01/04/09 13:29:46 changed by SantiagoZarate

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

(follow-ups: ↓ 4 ↓ 5 ) 01/04/09 22:33:19 changed 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....

(in reply to: ↑ 3 ) 01/04/09 23:26:55 changed by mattmcc

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

(in reply to: ↑ 3 ) 01/05/09 04:25:38 changed 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?.

(follow-up: ↓ 8 ) 01/05/09 09:10:35 changed 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...

01/05/09 09:28:21 changed by ramiro

I marked #9949 as duplicate of this.

(in reply to: ↑ 6 ) 01/05/09 11:26:21 changed by ramiro

  • keywords changed from liste_filter choices nested option gropus named tuples to list_filter choices nested option gropus named tuples.

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.

01/10/09 07:40:39 changed by ramiro

  • owner changed from SantiagoZarate to ramiro.
  • status changed from assigned to new.

02/26/09 09:16:22 changed by ramiro

  • status changed from new to closed.
  • resolution set to duplicate.

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.

Add/Change #9954 (admin change list: list_filter section breaks when using named groups in the choices field option)




Change Properties
Action