diff options
Diffstat (limited to 'django/db/models/fields')
| -rw-r--r-- | django/db/models/fields/files.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index 7c911f4b23..0716d3599e 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -9,6 +9,7 @@ from django.core.files.images import ImageFile from django.core.files.storage import Storage, default_storage from django.core.files.utils import validate_file_name from django.db.models import signals +from django.db.models.expressions import DatabaseDefault from django.db.models.fields import Field from django.db.models.query_utils import DeferredAttribute from django.db.models.utils import AltersData @@ -197,6 +198,12 @@ class FileDescriptor(DeferredAttribute): attr = self.field.attr_class(instance, self.field, file) instance.__dict__[self.field.attname] = attr + # If this value is a DatabaseDefault, initialize the attribute class + # for this field with its db_default value. + elif isinstance(file, DatabaseDefault): + attr = self.field.attr_class(instance, self.field, self.field.db_default) + instance.__dict__[self.field.attname] = attr + # Other types of files may be assigned as well, but they need to have # the FieldFile interface added to them. Thus, we wrap any other type of # File inside a FieldFile (well, the field's attr_class, which is |
