This is the model I am using to upload and rename image files in Django,
@deconstructible
class PathAndRename(object):
def __init__(self, sub_path):
self.path = sub_path
def __call__(self, instance, filename):
ext = filename.split('.')[-1]
filename = '{}.{}'.format(uuid4().hex, ext)
return os.path.join(self.path, filename)
class Diagram(models.Model):
diagram = models.FileField(upload_to=PathAndRename("diagrams/"))
text = models.CharField(max_length = 48)
date = models.DateTimeField(auto_now_add=True, blank=True, null=True)
Now the images are saved in both .jpg and .png as per its original format.
My question is how to make all the uploads, be it .jpg file or .png file to store in common format e.g. all images in .png file.