code: def delete_files(sender, **kwargs):
      
      instance = kwargs['instance']
  
      if not hasattr(instance.distribution, 'path'):
          return
  
      if not os.path.exists(instance.distribution.path):
          return
  
      # Check if there are other instances which reference this fle
      is_referenced = (
          instance.__class__.objects
          .filter(distribution=instance.distribution)
          .exclude(pk=instance._get_pk_val())
          .exists())
      if is_referenced:
          return
  
      try:
          instance.distribution.storage.delete(instance.distribution.path)
      except Exception:
          logger.exception(
              'Error when trying to delete file %s of package %s:' % (
                  instance.pk, instance.distribution.path))
docs: Signal callback for deleting old files when database item is deleted