[Fixed]-Django-filter: TypeError at /goods/ __init__() got an unexpected keyword argument 'name'

44👍

From the Migrating to 2.0 guide,

Filter.name renamed to Filter.field_name (#792)

The filter name has been renamed to field_name as a way to disambiguate the filter’s attribute name on its FilterSet class from the field_name used for filtering purposes.

So, from django-filter==2.0 onwards, use field_name instead of name

class GoodsFilter(filters.FilterSet):
    pricemin = filters.NumberFilter(field_name="shop_price", lookup_expr='gte')
    pricemax = filters.NumberFilter(field_name="shop_price", lookup_expr='lte')

    class Meta:
        model = Goods
        fields = ['pricemin', 'pricemax']
👤JPG

Leave a comment