Advertisement
Guest User

Untitled

a guest
Oct 18th, 2020
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. class UploadedImage(models.Model):
  2.     image = models.ImageField(unique=True)
  3.     input_url = models.URLField(blank=True)
  4.     image_hash = models.CharField(unique=True, max_length=32)
  5.     created_time = models.DateTimeField(auto_now_add=True)
  6.  
  7.     def save(self, *args, **kwargs):
  8.         hash_sha1 = hashlib.sha1()
  9.         for chunk in self.image.chunks():
  10.             hash_sha1.update(chunk)
  11.         self.image_hash = hash_sha1.hexdigest()
  12.         super(UploadedImage, self).save(*args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement