Opened 12 years ago

Last modified 8 years ago

#5833 closed

[newforms-admin] Custom FilterSpecs — at Version 7

Reported by: Honza Král Owned by: jkocherhans
Component: contrib.admin Version: master
Severity: Normal Keywords: nfa-someday list_filter filterspec nfa-changelist ep2008
Cc: Simon Litchfield, eallik@…, semente@…, andreas@…, mbencun@…, chenyuejie@…, djangoproject@…, jan.rzepecki@…, kmike84@…, eandre@…, Gonzalo Saavedra, ciantic@…, rvdrijst, eppsilon, ramusus@…, peimei@…, marcoberi@…, david@…, rmanocha@…, sciyoshi@…, Odin Hørthe Omdal, Sean Legassick, Alexander Koshelev, Marinho Brandão, Dan Fairs, timothy.broder@…, Michael Manfre, internet@…, Robin Breathe, bendavis78@…, 3point2, SafPlusPlus, krasniyrus@…, subsume@…, dirleyrls@…, Vitek Pliska, Salva Pinyol, Simon Charette, remco@…, rohit.aggarwal@…, guandalino Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by korpios)

One should be able to create custom FilterSpecs for the admin's list_filter interface.

Honza_Kral: I modified the filterspec definition to allow for users to register their own filters in admin. The mechanism is simple - I just reverted the order of the registry so that newly registered specs will come first. That way if you register your own filter via FilterSpec.register, it will be used before the default one.

Another approach by korpios is described in the comments.

Change History (9)

Changed 12 years ago by Honza Král

comment:1 Changed 12 years ago by jkocherhans

Owner: changed from nobody to jkocherhans
Status: newassigned

I really like the idea behind this, but I'd need to review the code closer and won't take the time to do it right now since it's a new feature. I'd rather focus on bugs preventing newforms-admin from being used.

comment:2 Changed 12 years ago by Honza Král

Also see #3400 for another ideas about filters which could benefit from this scheme...

comment:3 Changed 12 years ago by Brian Rosner

Keywords: nfa-someday added; newforms admin removed

This ticket isn't critical to merge newforms-admin into trunk. Tagging with nfa-someday.

comment:4 Changed 12 years ago by Yuri Baburov

How about FilterSpec.insert method to do prepend and FilterSpec.register to do append? discussed somewhere, no?

comment:5 Changed 11 years ago by korpios

I'm attaching my crack at this issue; in particular, I wanted to allow custom FilterSpecs that aren't associated with a field. This way, you can throw together a filter for fairly arbitrary queries.

Much of the field-specific code from FilterSpec has been moved out to a subclass, FieldFilterSpec; that should be used as the superclass for custom field-based filterspecs, while FilterSpec can be used for non-field-based ones.

The list_filter syntax gains two further options besides field names: a FilterSpec subclass, or a tuple of ('field_name', FieldFilterSpecSubclass).

An example combining all three:

list_filter = (
    ('field2', SomeFieldFilterSpec),

Changed 11 years ago by korpios

Custom FilterSpecs, also allowing fieldless FilterSpecs

comment:6 Changed 11 years ago by korpios

Cc: korpios@… added

comment:7 Changed 11 years ago by korpios

Description: modified (diff)
Summary: newforms-admin enable registering custom FilterSpecs[newforms-admin] Custom FilterSpecs

Tweaked the summary and description.

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