diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index 40b4e98026..f1c7468f48 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -118,7 +118,7 @@ class FileDescriptor(object): def __get__(self, instance=None, owner=None): if instance is None: - raise AttributeError, "%s can only be accessed from %s instances." % (self.field.name(self.owner.__name__)) + raise AttributeError("The '%s' attribute can only be accessed from %s instances." % (self.field.name, owner.__name__)) file = instance.__dict__[self.field.name] if not isinstance(file, FieldFile): # Create a new instance of FieldFile, based on a given file name diff --git a/tests/modeltests/files/models.py b/tests/modeltests/files/models.py index 3df3122cdb..373fa460ce 100644 --- a/tests/modeltests/files/models.py +++ b/tests/modeltests/files/models.py @@ -34,6 +34,12 @@ class Storage(models.Model): default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt') __test__ = {'API_TESTS':""" +# Attempting to access a FileField from the class raises a descriptive error +>>> Storage.normal +Traceback (most recent call last): +... +AttributeError: The 'normal' attribute can only be accessed from Storage instances. + # An object without a file has limited functionality. >>> obj1 = Storage()