我想在烧瓶管理中显示具有可计算字段(由python代码计算)的列。
我已经找到了下一步的方法:
将可计算的@property
添加到模型,然后将此属性添加到admin。
是否可以在不更改模型的情况下做到这一点?
答案 0 :(得分:1)
您可以声明不属于模型的任何数量的列字段,然后指定列格式化程序来提供这些列的数据,例如:
class TestView(ModelView):
# 'computed' is not in out model
column_list = ('name', 'subject', 'sent', 'recipients', 'computed')
def _computed_formatter(view, context, model, name):
# `view` is current administrative view
# `context` is instance of jinja2.runtime.Context
# `model` is model instance
# `name` is property name
return "Hello World"
column_formatters = {
'computed': _computed_formatter,
}