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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -