713 def delete_file self instance 714 if getattr instance self attname

1
2
3
4
5
6
7
8
713 def delete_file(self, instance):
714 if getattr(instance, self.attname):
715 file_name = getattr(instance, 'get_%s_filename' % self.name)()
716 # If the file exists and no other object of this type references it,
717 # delete it from the filesystem.
718 if os.path.exists(file_name) and \
719 not instance.__class__._default_manager.filter(**{'%s__exact ' % self.name: getattr(instance, self.attname)}):
720 os.remove(file_name)