How to access the model instance from custom flask admin template

混江龙づ霸主 提交于 2019-12-24 01:39:57

问题


I need to create a pretty complicated view of nested models in my admin page, googled all around the globe (form_edit_rules, edit_template, on_form_prefill), but could not find a way to access the current DB object from the flask-admin edit page.

How do I do this?


回答1:


The current DB object is passed as the variable model. See flask_admin/model/base.py ~ line 2077:

@expose('/edit/', methods=('GET', 'POST'))
def edit_view(self):

    # code

    model = self.get_one(id)

    # more code

    return self.render(template,
                           model=model,
                           form=form,
                           form_opts=form_opts,
                           return_url=return_url)


来源:https://stackoverflow.com/questions/52156201/how-to-access-the-model-instance-from-custom-flask-admin-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!