admin list_filter: limit choices to model values?

561 views
Skip to first unread message

Micky Hulse

unread,
Jan 13, 2012, 6:35:40 PM1/13/12
to django...@googlegroups.com
Hi.

Not sure where to start... Just hoping someone can give me a kick in
the right direction.

I have built a flat page app that allows for an author FK (optional field).

When I setup the admin to allow author as a list_filter, the actual
filter list of authors is way to long to be useful.

Would it be possible for me to setup my list_filter to only show
author names that have been assigned to my flat pages? For example,
let's say I have 10 pages, and two of those pages have the been FK'd
to "bjohnson" and "fjackson"... In my list_filter view, I would like
to only see "bjohnson" and "fjackson".

Does any of this make sense? :D

Any tips and/or advice would be awesome.

Thanks!
Micky

Micky Hulse

unread,
Jan 13, 2012, 6:54:13 PM1/13/12
to django...@googlegroups.com
Maybe simpler: Is there an easy way to limit the list_filter to folks
with "Superuser status"?

Micky Hulse

unread,
Jan 25, 2012, 5:18:45 PM1/25/12
to django...@googlegroups.com
On Fri, Jan 13, 2012 at 3:35 PM, Micky Hulse <rgm...@gmail.com> wrote:
> Would it be possible for me to setup my list_filter to only show
> author names that have been assigned to my flat pages? For example,
> let's say I have 10 pages, and two of those pages have the been FK'd
> to "bjohnson" and "fjackson"... In my list_filter view, I would like
> to only see "bjohnson" and "fjackson".

Just as an update, I found this:

<https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter>

... and it looks like what I need... Unfortunately, it's new in trunk
(I'm on 1.3).

I am hoping there's something similar to SimpleListFilter in 1.3.

I'm now trying to figure out how to browse Django source for version 1.3. :)

I will post back with more info if I figure something out.

Thanks!
Micky

Micky Hulse

unread,
Jan 25, 2012, 5:29:15 PM1/25/12
to django...@googlegroups.com
On Wed, Jan 25, 2012 at 2:18 PM, Micky Hulse <rgm...@gmail.com> wrote:
> I'm now trying to figure out how to browse Django source for version 1.3. :)

Cool, found 1.3 source:

django/branches/releases/1.3.X
<https://code.djangoproject.com/browser/django/branches/releases/1.3.X>

Looks like maybe FilterSpec might be what I want:

<https://code.djangoproject.com/browser/django/branches/releases/1.3.X/django/contrib/admin/filterspecs.py>

At least now I have a better idea of what to Google for "django
FilterSpec author". :)

Thanks!
Micky

JHeasly

unread,
Jan 30, 2012, 7:27:02 PM1/30/12
to django...@googlegroups.com
In 1.4/trunk, looks like filterspec.py gets replaced by filters.py (as part of adding the ability to filter a list_filter), so we'll just sit tight and wait for 1.4 to be released (rather than have to go  back and remove the defunct filterspec code).

— John

Micky Hulse

unread,
Feb 1, 2012, 4:59:45 PM2/1/12
to django...@googlegroups.com
Related to my original question:

On top of needing to limit list_filter in the admin, I also needed to
limit the user choices in my FK to auth.user. This bit of code does
just that:

<https://gist.github.com/1719713>

Just thought I would share the code to help others.

I am wondering if I can apply the same logic, as a method, to list_filter?

list_filter = SomeMethod()

(probably not, but that would be nice)

Anywho... Anyone know when Django 1.4 is scheduled to be released?

Micky Hulse

unread,
Feb 2, 2012, 5:35:01 PM2/2/12
to django...@googlegroups.com
On Wed, Feb 1, 2012 at 1:59 PM, Micky Hulse <rgm...@gmail.com> wrote:
> Anywho... Anyone know when Django 1.4 is scheduled to be released?

<http://bit.ly/zEbdFW>

[quote]

The Django 1.4 roadmap

Before the final Django 1.4 release, several other preview/development
releases will be made available. The current schedule consists of at
least the following:

* Week of January 30, 2012: First Django 1.4 beta release; final
feature freeze for Django 1.4.

* Week of February 27, 2012: First Django 1.4 release candidate;
string freeze for translations.

* Week of March 5, 2012: Django 1.4 final release.

If necessary, additional alpha, beta or release-candidate packages
will be issued prior to the final 1.4 release. Django 1.4 will be
released approximately one week after the final release candidate.

[/quote]

--<https://docs.djangoproject.com/en/dev/releases/1.4-alpha-1/#the-django-1-4-roadmap>

Reply all
Reply to author
Forward
0 new messages