python - Column formatters in Flask Admin interface -
hi have created flask admin interface. in 1 of field(column), include hyperlink.
class workout(db.model): equipment = db.column(db.string(100)) place = db.column(db.string(100)) image = db.column(db.text)
or using jinja2 macro in template:
i have create view should include above columns have format image column in view.
i not sure of how create view above mentioned custom class model.
from flask_admin.model.template import macro class workoutview(modelview):
in _macros.html file.
{% macro render_image() %} <a href="#" id="upload_widget_opener">upload images</a> <script src="https://widget.cloudinary.com/global/all.js" type="text/javascript"></script> <script type="text/javascript"> document.getelementbyid("upload_widget_opener").addeventlistener("click", function() { cloudinary.openuploadwidget({ cloud_name: 'mycloudname', sources: [ 'local', 'url', 'camera', 'image_search', 'facebook', 'dropbox', 'google_photos' ], upload_preset: 'myuploadpreset'}, function(error, result) { console.log(error, result) }); }, false); </script> {% endmacro %}
if run _macros.html file, , getting hyperlink expected. issue : not getting hyperlink in column formatted when try import macros _macros.html file
is there issue syntax in _macros.html or in app.py file ?
i think misuse sqlalchemy , flask-admin. custommodel class inherit db.model sqlalchemy , custommodelview class inherit modelview flask-admin control behavior of model in flask-admin. can achieve purpose follows:
use form_widget_args
add id
attribute form field;
inherit create.html
& edit.html
add javascript.
class examplemodelview(modelview): # ... edit_template = "admin/edit.html" create_template = "admin/create.html" form_widget_args = { "image": { "id": "cloudinary" } } # ... # template inherit. "edit.html" same "create.html" except first line. {% extends "admin/model/create.html" %} {% block tail %} {{ super() }} <script src="https://widget.cloudinary.com/global/all.js" type="text/javascript"></script> <script type="text/javascript"> # js code upload image , return response </script> {% endblock %}
Comments
Post a Comment