Will & Skill Developers

Will & Skill Developers


Thoughts, snippets and ideas from the team at Will & Skill AB, Stockholm.

Hassan Mian
Author

Don't let someone else's opinion of you become your reality. - Les Brown

Share


Tags


avrt

Unique image name

This should be used as default since all our projects stores files on S3 buckets def unique_image_name(instance, filename): # Prepends unique epoch timestam…

Hassan MianHassan Mian

This should be used as default since all our projects stores files on S3 buckets

def unique_image_name(instance, filename):
    # Prepends unique epoch timestamp on image filename
    directory = 'mysupercoolmodel/image'
    epoch_time = int(time.time())
    path = u"{}/{}-{}".format(directory, epoch_time, filename)
    return path
    
class MySuperCoolModel(models.Model):
	image = models.ImageField(upload_to=unique_image_name)
Hassan Mian
Author

Hassan Mian

Don't let someone else's opinion of you become your reality. - Les Brown

View Comments