1

I am building a django-filter FilterView, using ModelSelect2Widget for some of the filter form fields.

It correctly work to select items, and build the right query params in URL, but when I reload the page, passing the filter instance in the context, the ModelSelect2Widget does not display the previously selected item.

In template I checked that {{ filter.form.data }} effectively contains the selected data : it is OK.

In the principle, the codebase is like this :

class BookFilterSet(FilterSet):
   author = MethodFilter(widget=ModelSelect2Widget(
       queryset=User.objects.all(),
       search_fields=['username__icontains',]
   ),
   action = 'no_action'

   def no_action(self, queryset, name, value):
        """a neutral action"""
        return queryset

class FilterView(FilterView):
    filterset_class = BookFilterSet
    template_name = "books.html"

Do I need to override some method to display filter.form.initial in the ModelSelect2Widget ?

Timothé Delion
  • 1,310
  • 12
  • 17

0 Answers0