diff options
| author | Karen Tracey <kmtracey@gmail.com> | 2009-02-24 17:24:08 +0000 |
|---|---|---|
| committer | Karen Tracey <kmtracey@gmail.com> | 2009-02-24 17:24:08 +0000 |
| commit | 5f9ac288563ea6e8c9d25a7f7eeb1d437df28a8c (patch) | |
| tree | 9d3c00c4fe2d71675d10d785eb6eed8e4c6a9f18 | |
| parent | 7d03ca9e86e366c2c369101621d011eb6ee8b2c2 (diff) | |
Fixed #10347 -- Fixed incorrect AttributeError raised when attempting to access a FileField without an instance. Thanks for the report and patch dc.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9902 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/models/fields/files.py | 2 | ||||
| -rw-r--r-- | tests/modeltests/files/models.py | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py index f9bfc9d03f..7215897f16 100644 --- a/django/db/models/fields/files.py +++ b/django/db/models/fields/files.py @@ -122,7 +122,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 isinstance(file, basestring) or file is None: # 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 741a28411b..ba3eb99910 100644 --- a/tests/modeltests/files/models.py +++ b/tests/modeltests/files/models.py @@ -35,6 +35,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() |
