Ticket #8912: filefield_commit_8975.diff

File filefield_commit_8975.diff, 1.3 KB (added by shadfc, 16 years ago)

simpler patch which just requires save = True before "really doing stuff" in filefield save() and delete()

  • django/db/models/fields/files.py

     
    7171
    7272    def save(self, name, content, save=True):
    7373        name = self.field.generate_filename(self.instance, name)
    74         self._name = self.storage.save(name, content)
     74        if save:
     75            self._name = self.storage.save(name, content)
     76        else:
     77            self._name = '%s (unsaved)' % name
     78
    7579        setattr(self.instance, self.field.name, self.name)
    7680
    7781        # Update the filesize cache
     
    8993            self.close()
    9094            del self._file
    9195           
    92         self.storage.delete(self.name)
     96        if save:
     97            self.storage.delete(self.name)
    9398
    94         self._name = None
    95         setattr(self.instance, self.field.name, self.name)
     99            self._name = None
     100            setattr(self.instance, self.field.name, self.name)
    96101
    97         # Delete the filesize cache
    98         if hasattr(self, '_size'):
    99             del self._size
     102            # Delete the filesize cache
     103            if hasattr(self, '_size'):
     104                del self._size
    100105
    101         if save:
    102106            self.instance.save()
    103107    delete.alters_data = True
    104108
Back to Top