Fixed #32098 -- Made FieldFile use FileField.attname.

After a93425a37f FileDescriptor is a
subclass of DeferredAttribute and uses FileField.attname to access the
field data, so that custom subclasses can not only save data to files,
but also represent the same data with a different data type by
attaching FileFiled.name to a particular descriptor.

Follow up to a93425a37f.
This commit is contained in:
Sultan 2020-10-12 08:22:59 +03:00 committed by GitHub
parent 079deba530
commit 6599608c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -86,7 +86,7 @@ class FieldFile(File):
def save(self, name, content, save=True):
name = self.field.generate_filename(self.instance, name)
self.name = self.storage.save(name, content, max_length=self.field.max_length)
setattr(self.instance, self.field.name, self.name)
setattr(self.instance, self.field.attname, self.name)
self._committed = True
# Save the object because it has changed, unless save is False
@ -106,7 +106,7 @@ class FieldFile(File):
self.storage.delete(self.name)
self.name = None
setattr(self.instance, self.field.name, self.name)
setattr(self.instance, self.field.attname, self.name)
self._committed = False
if save: