Note that there are some explanatory texts on larger screens.

plurals
  1. POdjango admin filters cascading
    primarykey
    data
    text
    <p>I've got a question - can Django Admin interface be customized in such a way, that it presents only those filter options that occur in the subset of data matching currently selected filters?</p> <p>Say I have a db of three objects:</p> <pre><code>a.Foo = "One" a.Bar = "Drink" b.Foo = "One" b.Bar = "Shot" c.Foo = "Two" c.Bar = "Shot" </code></pre> <p>And a django admin interface with filters on 'Foo' and 'Bar'. I want the following behavior: </p> <ul> <li>If no filters are chosen, 'Foo' lists "One","Two"; 'Bar' lists "Drink", "Shot"</li> <li>If 'Foo' filter is set to "One", 'Bar' lists both "Drink" and "Shot"</li> <li>If 'Foo' filter is set to "Two", 'Bar' lists only "Shot"</li> <li>If 'Bar' filter is set to "Shot", 'Foo' lists both "One" and "Two"</li> <li>If 'Bar' filter is set to "Drink", 'Foo' lists only "One"</li> </ul> <p>Cheers!</p> <hr> <p>To be more specific - after reading some docs:</p> <pre><code>from django.contrib.admin import SimpleListFilter class SomeFilter(SimpleListFilter): title = "Foo" parameter_name="Some" def lookups(self, request, model_admin): qs = model_admin.queryset(request) print qs.query return (('Foo', 'Bar')) def queryset(self, request, queryset): if (self.value()): return queryset.filter(Some=self.value()) else: return queryset </code></pre> <p>What it does, however, is gets the 'queryset' as it would've been without other filters. How can I pass it through other filters?</p> <hr> <p>I could theoretically parse the request and filter manually - but there surely needs to be a way to pipe all filters.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload