简体   繁体   中英

Django filters, got an unexpected keyword argument

I'm using: 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'm using this:

site_filter = SiteFilter(user='test')

I've got:

init () got an unexpected keyword argument 'user'

I agree with @Ernest Ten. Looks like first thing you need to try is to change

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM