Opened 12 years ago

Last modified 8 weeks ago

#19755 assigned New feature

Incremental filter

Reported by: paulox@… Owned by: Przemysław Suliga
Component: contrib.admin Version: dev
Severity: Normal Keywords: filter, admin
Cc: suligap@…, Collin Anderson Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: yes

Description

Would be a good feature to have filter's value that change incrementally when user select one of them.

I try to explain with an example:

class Person(models.Model):
    name = models.CharField()
    hair_color = models.CharField()
    eye_color = models.CharField()

class PersonAdmin(admin.ModelAdmin):
    list_filter = ["hair_color", "eye_color"]

At first I'll see all hair color and eye color values in the filter.

When I select an hair color value from the filter I'll see only person with that hair color.

I would view in the eye color filter only distinct values of eye colors of person that have hair color I selected from the filter.

Attachments (1)

19755.diff (15.9 KB ) - added by Przemysław Suliga 12 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 by Nick Sandford, 12 years ago

Triage Stage: UnreviewedDesign decision needed

I was just about to close this as worksforme, because your description was a bit ambiguous -- you're proposing to remove choices from the list filters if you're already filtering on another value and the filtered set no longer contains all the choices.

i.e. you have three people:

[{
    'name': 'Bob',
    'hair_color': 'brown',
    'eye_color': 'blue'
}, {
    'name': 'Bruce',
    'hair_color': 'brown',
    'eye_color': 'hazel'
}, {
    'name': 'Brett',
    'hair_color': 'ginger',
    'eye_color': 'brown'
}]

and when you filter on brown hair, the list filter for eye color no longer lists brown, as there are now only two people in the filtered set and they have blue and hazel eyes.

Seems like an OK idea, though it does require backwards-incompatible changes to django.contrib.admin. Marking as DDN.

comment:2 by paulox@…, 12 years ago

Sorry for my ambiguous description.

You're example it's ok and I hope my idea will be implemented in Django 1.6 !

comment:3 by Aymeric Augustin, 12 years ago

I've found it useful to select several filters and check that no records matched. I think there's some value in showing all the options even if some of them don't have matching records.

comment:4 by paulox@…, 12 years ago

I think both cases are useful. You could choose one of two cases specifying it in the code ?

comment:5 by Aymeric Augustin, 12 years ago

This is a new feature, I suggest starting a discussion on the django-developers mailing list to see if it gets some traction.

A patch would help (at least a proof of concept).

comment:6 by paulox@…, 12 years ago

I'm sorry but I'm not a Django core developer and I'm not able to provide a proof of concept.

I hope you can submit this new feature on the django-developers mailing list and discuss with other django core developer.

comment:7 by Aymeric Augustin, 12 years ago

Large parts of the development of Django are done by people who aren't core developers :)

Last edited 12 years ago by Aymeric Augustin (previous) (diff)

comment:8 by Aymeric Augustin, 12 years ago

Resolution: wontfix
Status: newclosed

Since no one is sufficiently interested in the idea to write a patch, or even send a proposal to django-developers, I'm going to close this feature request.

by Przemysław Suliga, 12 years ago

Attachment: 19755.diff added

comment:9 by Przemysław Suliga, 12 years ago

Cc: suligap@… added
Has patch: set
Resolution: wontfix
Status: closednew

Patch makes all default FieldListFilters incremental if list_filter_incremental option is True for particular ModelAdmin.

Incremental filters will contain only choices which when clicked will result in non-empty changelist.

comment:10 by Przemysław Suliga, 12 years ago

Owner: changed from nobody to Przemysław Suliga
Status: newassigned

I would be happy to finish this patch if it gets any traction.

comment:11 by Collin Anderson, 6 years ago

Cc: Collin Anderson added
Patch needs improvement: set

comment:12 by Adam Johnson, 8 weeks ago

The queries to discover empty categories are now done in Django 5.0, when facets are enabled: https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.show_facets .

Perhaps facets could automatically hide empty categories?

Note: See TracTickets for help on using tickets.
Back to Top