Flask-admin内联建模传递表单参数抛出AttributeError [英] Flask-admin inline modelling passing form arguments throws AttributeError
问题描述
ContentNode
和 ContentData
。 我使用Docs inline_models / mod_contrib_sqla /rel =nofollow>这里,它似乎开始正常工作。
#AuthModelView (Model.ContentData,)
简单的ModelView和用户认证
class ContentNodeModelView(AuthModelView):
...
inline_models =然而,只要我尝试将属性传递给内联表单,使用
<$ p $ $ b> p>inline_models = [(models.ContentData,dict(form_columns = ['title','text']))]
Flask服务器给出
AttributeError:'ContentDataForm'对象没有属性'id '
我在这里丢失了超级明显的东西吗?有没有在文档中的错误,因为它听起来像也许 inline_models
期待一个模型,但得到一个字典?
我绝对检查过它与文档中的一样。
非常感谢任何帮助。感谢:)
您忘记指定id,它用于内联窗体构造。
尝试添加'id'属性:
$ p $ in $ inline_models = [(models.ContentData,dict(form_columns = [ 'id','title','text'])]]
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 :)
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']))]
这篇关于Flask-admin内联建模传递表单参数抛出AttributeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!