我正在研究内联模型,并且已经在这里测试了这个例子:
https://github.com/mrjoes/flask-admin/tree/master/examples/sqla-inline
我注意到如果将LocationImage模型/表的主键字段重命名为ID以外的其他字段,则不会触发after_delete处理程序。
所以这是有效的
image_id = db.Column(db.Integer, primary_key=True)
但如果我像这样重命名id列,
runat="server"
然后_handle_image_delete不会被调用。
我无法理解指定此字段的位置以及如何使用名为“id'”之外的PK的方法。
谢谢
答案 0 :(得分:0)
在field_list.html中,为主键呈现隐藏字段。您需要更改它以输出重命名的字段{{ field.form.image_id }}
。
{% import 'admin/model/inline_list_base.html' as base with context %}
{% macro render_field(field) %}
{% set model = field.object_data %}
{% if model and model.path %}
{{ field.form.image_id }}
<img src="{{ url_for('static', filename=model.path) }}" style="max-width: 300px;"></img>
{% else %}
{{ field }}
{% endif %}
{% endmacro %}
{{ base.render_inline_fields(field, template, render_field) }}