Opened 16 years ago

Last modified 12 years ago

#5833 closed

[newforms-admin] Custom FilterSpecs — at Version 7

Reported by: Honza Král Owned by: jkocherhans
Component: contrib.admin Version: dev
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)

comment:1 by jkocherhans, 16 years ago

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 by Honza Král, 16 years ago

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

comment:3 by Brian Rosner, 16 years ago

Keywords: nfa-someday added; newforms admin removed

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

comment:4 by Yuri Baburov, 16 years ago

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

comment:5 by korpios, 16 years ago

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 = (
    'field1',
    ('field2', SomeFieldFilterSpec),
    SomeFilterSpec,
)

by korpios, 16 years ago

Custom FilterSpecs, also allowing fieldless FilterSpecs

comment:6 by korpios, 16 years ago

Cc: korpios@… added

comment:7 by korpios, 16 years ago

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