【发布时间】:2021-04-12 00:47:58
【问题描述】:
【问题讨论】:
标签: flask sqlalchemy flask-sqlalchemy flask-wtforms flask-admin
【问题讨论】:
标签: flask sqlalchemy flask-sqlalchemy flask-wtforms flask-admin
将模型B中的字段添加到column_details_list(docs)
将模型 B 中的相同字段添加到 column_formatters_detail 字典 (docs),指定返回适当 HTML 的格式化程序方法。
例如:
from markupsafe import Markup
class ExampleView(AdminView):
# include the comments child field plus any parent fields from model A you want to show
column_details_list = ('name', 'last_name', 'comments')
def _comments_formatter(view, context, model, name):
# model is parent model A
_html = []
if model.comments:
# return any valid HTML markup
for _comment_model in model.comments:
# add html para per comment
_html.append(f'<p>User:{str(_comment_model.user)}, Comment:{_comment_model.comment}</p>')
return Markup(''.join(_html))
column_formatters_detail = {
'comments': _comments_formatter
}
【讨论】: