Flask-admin inline modelling passing form arguments throws AttributeError

强颜欢笑 提交于 2020-01-15 04:11:27

问题


Hi there fellow Flask developers!

In Flask-admin, I currently try to implement inline model editing into my model view. On the model side, I have a simple tree structure that represents a set of content pages. Each node has several child nodes and also several content data models associated with it. The models are named ContentNode and ContentData.

If I use the inline_models property on the node view class as described in the Docs here, it seems to work fine at first.

# AuthModelView is simply ModelView with user authentification
class ContentNodeModelView(AuthModelView):
    ...

    inline_models = (models.ContentData, )

However, as soon as I try to pass properties to the inline form, using

inline_models = [(models.ContentData, dict(form_columns=['title', 'text']))]

the Flask server gives

AttributeError: 'ContentDataForm' object has no attribute 'id'

Am I missing something super obvious here? Is there maybe a mistake in the documentation because it sounds like maybe inline_models expects a model but gets a dictionary?

I definitely checked that it's the same as in the docs.

Any help is greatly appreciated. Thanks :)


回答1:


You forgot to specify id, which uses for inline-form construction. Try to add 'id' attribute in:

inline_models = [(models.ContentData, dict(form_columns=['id', 'title', 'text']))]


来源:https://stackoverflow.com/questions/34313253/flask-admin-inline-modelling-passing-form-arguments-throws-attributeerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!