I have got an issue - can Django Admin interface be personalized in a way, it presents only individuals filter options that exist in the subset of information matching presently selected filters?

Say I've got a db of three objects:

a.Foo = "One"
a.Bar = "Drink"

b.Foo = "One"
b.Bar = "Shot"

c.Foo = "Two"
c.Bar = "Shot"

Along with a django admin interface with filters on 'Foo' and 'Bar'. I would like the next behavior:

  • If no filters are selected, 'Foo' lists "One","Two" 'Bar' lists "Drink", "Shot"
  • If 'Foo' filter is placed to "One", 'Bar' lists both "Drink" and "Shot"
  • If 'Foo' filter is placed to "Two", 'Bar' lists only "Shot"
  • If 'Bar' filter is placed to "Shot", 'Foo' lists both "One" and "Two"
  • If 'Bar' filter is placed to "Drink", 'Foo' lists only "One"


To become more specific - after reading through some paperwork:

from django.contrib.admin import SimpleListFilter

class SomeFilter(SimpleListFilter):
  title = "Foo"
  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())
      return queryset

What it really does, however, is will get the 'queryset' because it would have been without other filters. How do i pass it through other filters?

I possibly could theoretically parse the request and filter by hand - but there surely must be a method to pipe all filters..

This type of dynamic blocking really appears like faceting. When you may have the ability to accomplish this result having a standard queryset, this can most likely 't be optimal. You might have more chance utilizing a devoted tool, like Solr.

Haystack has also a doc page on faceting.