multi-select admin filter for RelatedFields

903 views
Skip to first unread message

Marc Boeren

unread,
May 10, 2006, 6:23:32 PM5/10/06
to Django developers
Hi,

I've hacked my way into the admin filters, changing the
RelatedFilterSpec from a single-select filter to a multi-select filter.

I can now filter on multiple values from the same ManyToMany or
ForeignKey relationship, i.e. if I add 'groups' to the list_filter for
Users, I can select all users that fall into the Admin or the Editor
group (or both, or more).

Would this be a useful replacement for the current version, or could it
become an addition to the current filter methods?

I plan to do some more work on it (basically, a specifier to indicate
if you want OR or AND for your multiple selection, it is now OR only
(and AND will only work for ManyToMany of course)).

Should I create a ticket for this and attach a patch?

Ciao, Marc.
(I posted a similar message on Django users yesterday but I think it is
more appropriate here)

patrickk

unread,
May 11, 2006, 3:29:08 AM5/11/06
to django-d...@googlegroups.com
just a comment because noone else is answering:

- i can think of using that functionality
- AND would be important for me
- don´t know if a ticket is appropriate (see: http://
code.djangoproject.com/changeset/2830)

patrick

Marc Boeren

unread,
May 14, 2006, 2:45:32 PM5/14/06
to Django developers
A preliminary patch can be found at
http://www.million.nl/file/marc/django/multi-select-relatedfilterspec.diff

Screenshots for and/or will make it clear what this patch does :-)
http://www.million.nl/file/marc/django/multi-select-relatedfilterspec-and.gif
http://www.million.nl/file/marc/django/multi-select-relatedfilterspec-or.gif

Known bugs:
If there are no results, e.g. when combined with one of the other
filters, all filters revert back to 'All'. This is probably some
exception somewhere that I will track down soon

Unknown bugs:
I have to find out what happens when there is more than one
RelatedFilterSpec set for the admin-view.

More later!

Ciao, Marc.

Marc Boeren

unread,
May 14, 2006, 6:07:59 PM5/14/06
to Django developers
Update: the known bug is solved, the complete patch is now:
http://www.million.nl/file/marc/django/multi-select-relatedfilterspec.2.diff

This also solves the recordcount mismatch in the results view.

On a side note: if you have trouble with hidden Exceptions (as I had in
this case), it really helps if you change the lines (603+604 in
contrib.admin.views.main) from
except:
raise IncorrectLookupParameters

temporarily into
except:
raise

Ciao, Marc.

Michael Radziej

unread,
May 14, 2006, 11:24:40 PM5/14/06
to django-d...@googlegroups.com

Am 15.05.2006 um 00:07 schrieb Marc Boeren:

>
> Update: the known bug is solved, the complete patch is now:
> http://www.million.nl/file/marc/django/multi-select-
> relatedfilterspec.2.diff

Though I can't currently use admin pages at all, this looks cute. Why
don't you open a ticket and provide it as a patch? Even if it is
rejected, it's much easier to find useful patches this way.


Michael

Marc Boeren

unread,
May 15, 2006, 3:42:25 AM5/15/06
to Django developers
Reply all
Reply to author
Forward
0 new messages