Flask-admin内联建模传递表单参数抛出AttributeError [英] Flask-admin inline modelling passing form arguments throws AttributeError

查看:281
本文介绍了Flask-admin内联建模传递表单参数抛出AttributeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Flask-admin中,我现在尝试在模型视图中实现内联模型编辑。在模型方面,我有一个简单的树结构,代表一组内容页面。每个节点都有几个子节点,还有几个与之关联的内容数据模型。模型被命名为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆