def delete_files(sender, **kwargs):
instance = kwargs['<STR_LIT>']<EOL>if not hasattr(instance.distribution, '<STR_LIT:path>'):<EOL><INDENT>return<EOL><DEDENT>if not os.path.exists(instance.distribution.path):<EOL><INDENT>return<EOL><DEDENT>is_referenced = (<EOL>instance.__class__.objects<EOL>.filter(distribution=instance.distribution)<EOL>.exclude(pk=instance._get_pk_val())<EOL>.exists())<EOL>if is_referenced:<EOL><INDENT>return<EOL><DEDENT>try:<EOL><INDENT>instance.distribution.storage.delete(instance.distribution.path)<EOL><DEDENT>except Exception:<EOL><INDENT>logger.exception(<EOL>'<STR_LIT>' % (<EOL>instance.pk, instance.distribution.path))<EOL><DEDENT>
Signal callback for deleting old files when database item is deleted