1.使用xadmin时编写生鲜超市后台时,在商品信息报错
'NoneType' object has no attribute '_meta'
哪个模块报错就去看哪里的代码,检查了下发现是自己多谢了一个单词
正确的应该是
2.使用django_filters时出现
TypeError: __init__() got an unexpected keyword argument 'name'
按照DRF文档 配置django_filters 筛选,
在看了django_filters 官方文档示例后将name 更换为field_name后正常。
class GoodsFilter(django_filters.rest_framework.FilterSet):
'''
商品过滤的类
'''
#两个参数,name时要过滤的字段,lookup是执行的行为,小鱼等于本店的价格
price_min = django_filters.NumberFilter(field_name="shop_price",lookup_expr='gte')
price_max = django_filters.NumberFilter(field_name="shop_price",lookup_expr='lte')
class Meta:
model = Goods
fields = ['price_min','price_max']