code: def save(self, **kwargs):
          
          if not self.width or not self.height:
              self.width, self.height = self.image.width, self.image.height
  
          # prefill the slug with the ID, it requires double save
          if not self.id:
              img = self.image
  
              # store dummy values first...
              w, h = self.width, self.height
              self.image = ''
              self.width, self.height = w, h
              self.slug = ''
  
              super(Photo, self).save(force_insert=True)
  
              # ... so that we can generate the slug
              self.slug = str(self.id) + '-' + slugify(self.title)
              # truncate slug in order to fit in an ImageField and/or paths in Redirects
              self.slug = self.slug[:64]
              # .. tha will be used in the image's upload_to function
              self.image = img
              # and the image will be saved properly
              super(Photo, self).save(force_update=True)
          else:
              try:
                  old = Photo.objects.get(pk=self.pk)
  
                  force_update = True
                  # delete formatedphotos if new image was uploaded
                  if old.image != self.image:
                      for f_photo in self.formatedphoto_set.all():
                          f_photo.delete()
              except Photo.DoesNotExist:
                  # somebody is just trying to create new model with given PK
                  force_update = False
  
              super(Photo, self).save(force_update=force_update)
docs: Overrides models.Model.save.
  
          - Generates slug.
          - Saves image file.