问题
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