Ilya Bibik
Ilya Bibik

Reputation: 4124

django-filters ModelChoiceFilter does nothing

I am trying to add a drop down into my django filter for thisI am using ModelChoiceFilter

below is the relevant content of my model.py

However nothing happens and the test input remains the same ?Any idea why it is happening?

BTW any feedback on how task of having controlled input in filter can be resolved in django better then just drop down -- you are very welcome to provide your feedback. It will be not possible for the user to use the drop down when the amount of data will be huge.

 class CompanyFilter(django_filters.FilterSet):
        class Meta:
            model = Company
            fields = ['author','updated_by','name','country', 'state_province',
            'city','zip_code','phone',
            'zip_code','keywords']

            name = django_filters.ModelChoiceFilter(queryset=Company.objects.all().order_by('name')

Upvotes: 2

Views: 1282

Answers (1)

M.Doody
M.Doody

Reputation: 41

Try this:

class CompanyFilter(django_filters.FilterSet):
    name=django_filters.ModelChoiceFilter(queryset=Company.objects.all().order_by('name'))
    class Meta:
        model = Company
        fields = ['author','updated_by','name','country', 'state_province',
        'city','zip_code','phone',
        'zip_code','keywords']

read this https://django-filter.readthedocs.io/en/develop/ref/filters.html#modelchoicefilter

Upvotes: 1

Related Questions