JiayangYing / CITS3403_PRO

MIT License
2 stars 0 forks source link

Image upload #94

Closed JiayangYing closed 4 months ago

JiayangYing commented 4 months ago

This pull request introduces enhancements to enable image uploads associated with products. Changes include adding an Image model in models.py to store image information and updating the ProductForm to handle image uploads. App configuration for file uploads is added, defining UPLOAD_FOLDER and UPLOAD_EXTENSIONS to specify the upload directory and allowed file types. The validate_image function in routers.py checks the validity of uploaded images, ensuring only valid images are accepted. Additionally, a helper function validate_images validates multiple images before saving them. The add_product function is modified to save images correctly, using database transactions to ensure both product and images are saved atomically, with error handling to maintain data integrity. These changes collectively enhance the product management functionality, providing a robust and user-friendly experience.