@receiver(models.signals.post_delete, sender=File, dispatch_uid='cleanup_file')
def cleanup_file(sender, instance, **kw):
 if (kw.get('raw') or (not instance.filename)):
  return
 for path in ('file_path', 'guarded_file_path', 'reviewer_signed_file_path', 'signed_file_path'):
  try:
   filename = getattr(instance, path, None)
  except models.ObjectDoesNotExist:
   return
  if (filename and (public_storage.exists(filename) or private_storage.exists(filename))):
   log.info(('Removing filename: %s for file: %s' % (filename, instance.pk)))
   public_storage.delete(filename)
   private_storage.delete(filename)

@ receiver ( models . signals . post_delete , sender = File , dispatch_uid = 'cleanup_file' ) def cleanup_file ( sender , instance , ** kw ) : if ( kw . get ( 'raw' ) or ( not instance . filename ) ) : return for path in ( 'file_path' , 'guarded_file_path' , 'reviewer_signed_file_path' , 'signed_file_path' ) : try : filename = getattr ( instance , path , None ) except models . ObjectDoesNotExist : return if ( filename and ( public_storage . exists ( filename ) or private_storage . exists ( filename ) ) ) : log . info ( ( 'Removing filename: %s for file: %s' % ( filename , instance . pk ) ) ) public_storage . delete ( filename ) private_storage . delete ( filename )
on delete of the file object from the database .