Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask-admin inline modelling passing form arguments throws AttributeError

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 :)

like image 409
RobinWeiss Avatar asked Dec 16 '15 13:12

RobinWeiss


1 Answers

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']))]
like image 148
bychok.vl Avatar answered Nov 14 '22 23:11

bychok.vl