环境:xadmin-for-python3 python3.5.2 django1.9.12
问题描述:Product ProductSku两个实体,ProductSku FK外键关联Product ,Product 列表页的filter不支持productsku__sku_code的搜索,主要页面加载时报Product has no field named ‘sku_code’
解决办法:
xadmin\util.py文件中def get_model_from_relation(field):
django的get和filter方法是django model常用到的,搞清楚两者的区别非常重要。
为了说明它们两者的区别定义2个models
class Student(models.Model):
name = models.CharField('姓名', max_length=20, default='')
age = models.CharField('年龄', max_length=20, default='')
class Book(models.Model):
student
python 内置函数filter
class filter(object):
filter(function or None, iterable) --> filter object
Return an iterator yielding those items of iterable for which function(item)
is true. If function is None, return the items that are true.
filter