Django-filter报错:__init__() got an unexpected keyword argument 'name'

原因是 自从 django-filter2.0之后 将Filter的name字段 更名为 field_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']
 

posted @ 2019-07-08 22:36  糖宝虫  阅读(4546)  评论(0编辑  收藏  举报