[Answered ]-Saving images from Django database in a management command

2👍

Images (or other FileFields) are actually regular files stored in somewhere (like a file system or a block storage like S3). Assuming that your files reside on the server’s file system, you can use the path property to get the original file path and use Python shell utilities to copy it to another location:

import shutil

for m in my_models.objects.filter(get=some):
    image = m.image 
    shutil.copy(image.path, '/var/tmp/')
👤Selcuk

Leave a comment