如何自定义Flask-Admin模块的内联模型视图/表单?

时间:2016-09-01 09:23:59

标签: 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,我可以添加信息Click here to authenticate to Google

我不确定是否需要为GoogleAcountApi添加子视图

谢谢!

1 个答案:

答案 0 :(得分:1)

找到它here,这就是你要做的:

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