1

Using the "List_Filter" in admin, I would like to modify it to only show fields that have content (according to the filter).

Easiest to explain through an example.

For example,

When selecting a Category filter (eg Sunglasses), the Brand filter list will only list Brands that contain Sunglasses in its' filter.

Does that make sense?

How can this be achieved?

3
  • It is hard to understand exactly what you mean w/o knowing what your models look like. Can you show what your models and filters look like? Nov 16, 2015 at 5:47
  • This might be what you are asking: stackoverflow.com/questions/9707002/… Nov 16, 2015 at 5:57
  • I want to make Django do this automatically- so that I dont have to create customlistfilters individually.
    – Yian
    Nov 18, 2015 at 0:49

1 Answer 1

2

I might think that u have to select the Next Filter according to the previous Filter.. Try to get request from the url where you pass the data

def lookups(self, request, model_admin):

    if request.GET.get('previous_filter') == 'True':
       return []

    if request.GET.get('current_filter') == 'False':
        return [
          # Pass your List Here
        ]
    if self.value() is None:
        return []

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.