files_13.py 442 B

123456789101112
  1. def save(self, name, content, save=True):
  2. name = self.field.generate_filename(self.instance, name)
  3. self.name = self.storage.save(name, content)
  4. setattr(self.instance, self.field.name, self.name)
  5. # Update the filesize cache
  6. self._size = content.size
  7. self._committed = True
  8. # Save the object because it has changed, unless save is False
  9. if save:
  10. self.instance.save()