Flask-admin inline modelling passing form arguments throws AttributeError
Asked Answered
U

1

7

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

Umbelliferous answered 16/12, 2015 at 13:24 Comment(2)
Why editing forms when sending it ? Rebuild your form before publishing !Thorin
Thanks for the reply! Where would I pass the rebuilt form exactly?Umbelliferous
S
9

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']))]
Sailer answered 6/4, 2016 at 11:33 Comment(1)
Great answer, can't believe this wasn't in the documentationIsleen

© 2022 - 2024 — McMap. All rights reserved.