Django filters received unexpected keyword argument

I use: http://django-filter.readthedocs.org/en/latest/usage.html and I have a problem with this code:

class BasicFilter(django_filters.FilterSet):
    class Meta:
        model = MyModel
        fields = []

class SiteFilter(BasicFilter):
    site = django_filters.ModelMultipleChoiceFilter(
        queryset=Site.objects.all(), help_text=''
    )
    def __init__(self, *args, **kwargs):
        print kwargs
        super(BrowserFilter, self).__init__(*args, **kwargs)
    class Meta(ReportFilter.Meta):
        fields = ['site']

And when I use this:

site_filter = SiteFilter(user='test')

I have:

init () received an unexpected keyword argument to 'user'

+4
source share
1 answer

I agree with @Ennest Ten. Seems like the first thing you need to try is change

super(BrowserFilter, self).__init__(*args, **kwargs)

to

super(SiteFilter, self).__init__(*args, **kwargs)
0
source

Source: https://habr.com/ru/post/1612595/


All Articles