You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

17 regels
430 B

  1. import hashlib
  2. import os
  3. def upload_path(instance, filename, **kwargs):
  4. hasher = hashlib.md5()
  5. for chunk in instance.image.chunks():
  6. hasher.update(chunk)
  7. hash = hasher.hexdigest()
  8. base, ext = os.path.splitext(filename)
  9. return '%(first)s/%(second)s/%(hash)s/%(base)s%(ext)s' % {
  10. 'first': hash[0],
  11. 'second': hash[1],
  12. 'hash': hash,
  13. 'base': base,
  14. 'ext': ext,
  15. }