← Back to team overview

canonical-django team mailing list archive

Re: list_filter for showing null dates

 

On Tue, Nov 3, 2009 at 4:17 PM, Matthew Nuzum <newz@xxxxxxxxxxxxx> wrote:
> On Tue, Nov 3, 2009 at 3:21 PM, Stuart Metcalfe
> <stuart.metcalfe@xxxxxxxxxxxxx> wrote:
>> you should be able to extend the default admin filters to achieve the
>> functionality you're after.  I haven't checked if this is supported in
>> 0.96.
>>
>
> Ugh.
>
> "You have to write a custom FilterSpec (not documented anywhere)."
>

This is possible in 0.96 and it's really not too bad to do.

I will point out an alternate, maybe easier, but a bit hackish way to
a similar end result if all you want is objects where expires is null.
 If you didn't know, you can URL hack the admin with any query, so
something like this will work:

http://localhost:8000/admin/myproject/myapp/?expires__isnull=True

So given that, you can create an admin directory that is discoverable
on your TEMPLATE_DIRS path, and cp filter.html from
django/contrib/admin/templates/admin to $TEMPLATE_DIRS/admin/.  Then
add a simple:

<li><a href="?expires__isnull=True">Null expires date</a></li>

You can also do an app specific change list template (via
$TEMPLATE_DIRS/admin/myapp/change_list.html) and some hacking in the
filters block to get this to only show up for one app if need be.  You
could also add a bit of app-specific js to add the link on certain
views.  I'll leave it to the creative mind to go further with ways
this URL hacking could get what you want without a custom FilterSpec.
:)

Cheers,
deryck


-- 
Deryck Hodge
https://launchpad.net/~deryck
http://www.devurandom.org/



References