Ticket #4339: file_field_delete_file_on_update.2.diff
File file_field_delete_file_on_update.2.diff, 1.2 KB (added by , 17 years ago) |
---|
-
db/models/fields/__init__.py
769 769 file_name = getattr(instance, 'get_%s_filename' % self.name)() 770 770 # If the file exists and no other object of this type references it, 771 771 # delete it from the filesystem. 772 manager = instance.__class__._default_manager 772 773 if os.path.exists(file_name) and \ 773 not instance.__class__._default_manager.filter(**{'%s__exact' % self.name: getattr(instance, self.attname)}):774 not manager.filter(**{'%s__exact' % self.name: getattr(instance, self.attname)}).exclude(pk=instance._get_pk_val()): 774 775 os.remove(file_name) 775 776 776 777 def get_manipulator_field_objs(self): … … 781 782 782 783 def save_file(self, new_data, new_object, original_object, change, rel, save=True): 783 784 upload_field_name = self.get_manipulator_field_names('')[0] 785 if original_object: 786 self.delete_file(original_object) 784 787 if new_data.get(upload_field_name, False): 785 788 func = getattr(new_object, 'save_%s_file' % self.name) 786 789 if rel: