I would like to store images directly into the database i have been trying this but does not seem to help or i may be doing it in the wrong way''
models.py
from database_storage import DatabaseStorage
DB_FILES = {
'table': 'files',
'base_url': '/blog/attach/',
}
class Img(models.model):
uploaded_map_16 = models.ImageField(upload_to="map_images", storage=DatabaseStorage(DB_FILES), null=True, blank=True)
uploaded_map_17 = models.ImageField(upload_to="map_images", storage=DatabaseStorage(DB_FILES), null=True, blank=True)
uploaded_map_18 = models.ImageField(upload_to="map_images", storage=DatabaseStorage(DB_FILES), null=True, blank=True)
this is how i am trying to save it:
storage = DatabaseStorage(DB_FILES)
image_file1 = open(file_name_18, 'rb')
file_content1 = image_file1.read()
image_file2 = open(file_name_17, 'rb')
file_content2 = image_file2.read()
image_file3 = open(file_name_16, 'rb')
file_content3 = image_file3.read()
Img.uploaded_map_18 = storage.save(name + '_18.jpg', file_content1)
Img.uploaded_map_17 = storage.save(name + '_17.jpg', file_content2)
Img.uploaded_map_16 = storage.save(name + '.jpg', file_content3)
Img.save()