From 6599608c4d0befdcb820ddccce55f183f247ae4f Mon Sep 17 00:00:00 2001 From: Sultan Date: Mon, 12 Oct 2020 08:22:59 +0300 Subject: [PATCH] Fixed #32098 -- Made FieldFile use FileField.attname. After a93425a37f4defdb31d4ca96bb3bf6da21f0b5ce 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 a93425a37f4defdb31d4ca96bb3bf6da21f0b5ce. --- django/db/models/fields/files.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index db2450a738..d410771cf3 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -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: