From 98e8da3709e400d549e87c7ff1450a2685c0adcf Mon Sep 17 00:00:00 2001 From: Stanislas Guerra Date: Wed, 21 May 2014 12:32:19 +0200 Subject: Fixed #16311 -- Added a RelatedOnlyFieldListFilter class in admin.filters. --- docs/ref/contrib/admin/index.txt | 14 ++++++++++++++ docs/releases/1.8.txt | 5 +++++ 2 files changed, 19 insertions(+) (limited to 'docs') diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt index 958551d660..8d69ac6e82 100644 --- a/docs/ref/contrib/admin/index.txt +++ b/docs/ref/contrib/admin/index.txt @@ -880,6 +880,20 @@ subclass:: ('is_staff', admin.BooleanFieldListFilter), ) + .. versionadded:: 1.8 + + You can now limit the choices of a related model to the objects + involved in that relation using ``RelatedOnlyFieldListFilter``:: + + class BookAdmin(admin.ModelAdmin): + list_filter = ( + ('author', admin.RelatedOnlyFieldListFilter), + ) + + Assuming ``author`` is a ``ForeignKey`` to a ``User`` model, this will + limit the ``list_filter`` choices to the users who have written a book + instead of listing all users. + .. note:: The ``FieldListFilter`` API is considered internal and might be diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 07dd783d0b..9634b04db4 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -39,6 +39,11 @@ Minor features :attr:`~django.contrib.admin.InlineModelAdmin.show_change_link` that supports showing a link to an inline object's change form. +* Use the new ``django.contrib.admin.RelatedOnlyFieldListFilter`` in + :attr:`ModelAdmin.list_filter ` + to limit the ``list_filter`` choices to foreign objects which are attached to + those from the ``ModelAdmin``. + :mod:`django.contrib.auth` ^^^^^^^^^^^^^^^^^^^^^^^^^^ -- cgit v1.3