python - Attaching file to model with flask-admin -
i'm using flask-admin provide administrative interface website. how can handle file upload sqlalchemy model, such as
class product(db.model): __tablename__ = 'products' id = db.column(db.integer, primary_key=true) title = db.column(db.string(5000)) text_short = db.column(db.string(3000)) text = db.column(db.string(50000)) price = db.column(db.integer) image = db.column(db.string(1000)) , image field want store path image in /static directory?
override on_model_change , upload logic there: http://flask-admin.readthedocs.org/en/latest/api/mod_model/#flask.ext.admin.model.basemodelview.on_model_change
so, here's high level steps:
- either contribute filefield form, or change type of image field filefield
- in
on_model_changecopy uploaded file static folder , update modelimagefield new file path
hope helps.
Comments
Post a Comment