Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inline_models and query_factory together causing error #1635

Open
rulai-huajunzeng opened this issue Apr 11, 2018 · 1 comment
Open

inline_models and query_factory together causing error #1635

rulai-huajunzeng opened this issue Apr 11, 2018 · 1 comment

Comments

@rulai-huajunzeng
Copy link

I was trying to add a default filtering to an inline model, but got the following error.

TypeError: __init__() got an unexpected keyword argument 'query_factory'

Spent several hours on this but can't figure out how to solve it.

The following is the code causing error. I just added the following form_args to the sqla-inline example.

class LocationAdmin(ModelView):
    inline_model_form_converter = CustomInlineModelConverter

    inline_models = (InlineModelForm(),)

    form_args = {
        'images': {
            'query_factory': lambda: db.session.query(LocationImage)
        }
    }

    def __init__(self):
        super(LocationAdmin, self).__init__(Location, db.session, name='Locations')
@PATAPOsha
Copy link

PATAPOsha commented May 21, 2018

Had a same issue. Succeeded with overriding 'query_factory' of embedded form inside create_form/edit_form.
In your case it probably will be following:

def create_form(self, obj=None):
        form = super().create_form(obj)
        form.images.form.image.kwargs['query_factory'] = lambda: db.session.query(LocationImage)
        return form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants