[Fixed]-Django: add filtering sidebar to a change list admin view

1👍

You can use class based generic views

from django.views import generic

class MyListView(generic.ListView):
    model = MyModel
    template_name = 'my_list.html'

    def get_queryset(self):
        queryset = super(MyListView, self).get_queryset()
        # get query value of query parameter 'type'
        type = self.request.GET.get('type', None)

        if type:
            # if type is given then filter
            return queryset.filter(type__exact=type)
        # if type is not give then return all
        return queryset

You can refer to docs here

Leave a comment