7: Working with Images
Activity 11: Implementing the Recipe Cover Image Upload Function
Solution
- Add the
cover_image
attribute to the User model inmodels/recipe.py
:cover_image = db.Column(db.String(100), default=None)
The
cover_image
attribute will contain the image filename as a string, with a maximum length of 100 characters. - Use the flask db migrate command to generate a database table update script:
flask db migrate
You will see that a new column,
'recipe.cover_image'
, has been detected:INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. INFO [alembic.autogenerate.compare] Detected added column 'recipe.cover_image' Generating /TrainingByPackt/Python-API-Development-Fundamentals/Lesson07/smilecook/migrations/versions/91c7dc71b826_.py ... done
- Check the script at
/migrations/versions/xxxxxxxxxx_.py
:"""empty message...