python - 如何定制 Flask-Admin 模块的内联模型 View /表单?

标签 python flask flask-admin

假设我有这个父模型:

class GoogleAccount(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String, index=True)

class GoogleAccountApi(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    client_secret = db.Column(db.String)
    token = db.Column(db.String)

    google_account_id = db.Column(db.Integer, db.ForeignKey(GoogleAccount.id))
    google_account = db.relationship(GoogleAccount, backref=db.backref('google_account_id', cascade="all, delete-orphan", single_parent=True))


class GoogleAccountView(_ModelView):
    inline_models = (models.GoogleAccountApi,)
    column_descriptions = dict(
        email='Halooo'
    )

    admin.add_view(GoogleAccountView(models.GoogleAccount, db.session, endpoint='google-account'))

我知道我可以使用 column_descriptions 添加父模型 (GoogleAccount) 的列描述,但如何修改子模型列描述?这样,对于 GoogleAccountAPI.client_secrets,我可以添加信息:单击此处向 Google 进行身份验证

不确定是否需要为 GoogleAcountApi 添加 subview

谢谢!

最佳答案

找到了here ,所以这就是你要做的:

inline_models = [(models.GoogleAccountApi, dict(
    column_descriptions=dict(client_secret='Retoken here')
))]

关于python - 如何定制 Flask-Admin 模块的内联模型 View /表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39267649/

相关文章:

python - SQLAlchemy 使用过滤器映射表列

python - Flask-Admin 具有多对多关系中的附加字段

Python音频分析: find real time values of the strongest beat in each meter

python - 尝试绘制对应于 x,y,z 的 3 个不同数组

python - Celery 和 RabbitMQ 配置

python - 根据 Julia 中的数据绘制 3D 曲面(使用绘图)

python - PyMongo 添加电子邮件?

python - .ttf 文件导致 Travis CI 中的构建错误

python - Flask-Admin:同时在两个表中插入数据

javascript - 将数据从javascript表单传递到Flask服务器