In a web application that I code using Flask / SQLAlchemy, some of my models need a βPhotoβ column type that would handle storing the original image somewhere in the file system and create different sizes of image thumbnails. Ideally, Id wants something like:
class MyModel(Base): id = Column(Integer, primary_key=True) photo = Column(Photo(root="/path/to/photos/", formats={ "big" : "800x600", "small" : "400x300", "thumbnail": "100x75" }))
and then I could access the file URI / URL like this: model.photo.big etc.
So my question is: how to add setters / getters to the model.photo object so that I can access URIS / URLS with the specified syntax? By the way, if someone has a good tutorial / resource (other than an official document) on user types with SQLAlchemy, I would appreciate it if I could share it.
thanks.
python flask flask-sqlalchemy sqlalchemy
arnaud briche
source share