def save(self) -> None:
        """
        Saves all changed values to the database.
        """
        for name, field in self.fields.items():
            value = self.cleaned_data[name]
            if isinstance(value, UploadedFile):
                # Delete old file
                fname = self._s.get(name, as_type=File)
                if fname:
                    try:
                        default_storage.delete(fname.name)
                    except OSError:  # pragma: no cover
                        logger.error('Deleting file %s failed.' % fname.name)

                # Create new file
                newname = default_storage.save(self.get_new_filename(value.name), value)
                value._name = newname
                self._s.set(name, value)
            elif isinstance(value, File):
                # file is unchanged
                continue
            elif isinstance(field, forms.FileField):
                # file is deleted
                fname = self._s.get(name, as_type=File)
                if fname:
                    try:
                        default_storage.delete(fname.name)
                    except OSError:  # pragma: no cover
                        logger.error('Deleting file %s failed.' % fname.name)
                del self._s[name]
            elif value is None:
                del self._s[name]
            elif self._s.get(name, as_type=type(value)) != value:
                self._s.set(name, value)
def save ( self ) -> None : for name , field in self . fields . items ( ) : value = self . cleaned_data [ name ] if isinstance ( value , UploadedFile ) : fname = self . _s . get ( name , as_type = File ) if fname : try : default_storage . delete ( fname . name ) except OSError : logger . error ( 'Deleting file %s failed.' % fname . name ) newname = default_storage . save ( self . get_new_filename ( value . name ) , value ) value . _name = newname self . _s . set ( name , value ) elif isinstance ( value , File ) : continue elif isinstance ( field , forms . FileField ) : fname = self . _s . get ( name , as_type = File ) if fname : try : default_storage . delete ( fname . name ) except OSError : logger . error ( 'Deleting file %s failed.' % fname . name ) del self . _s [ name ] elif value is None : del self . _s [ name ] elif self . _s . get ( name , as_type = type ( value ) ) != value : self . _s . set ( name , value )
Saves all changed values to the database.