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:

  1. either contribute filefield form, or change type of image field filefield
  2. in on_model_change copy uploaded file static folder , update model image field new file path

hope helps.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -