Fixed #21042 -- Allowed accessing FileDescriptor on the model class.
This is consistent with ability to reference other descriptors
on the model class (5ef0c03ae9
).
This commit is contained in:
parent
8a5a002f2f
commit
9f6b704769
|
@ -157,9 +157,7 @@ class FileDescriptor(object):
|
||||||
|
|
||||||
def __get__(self, instance=None, owner=None):
|
def __get__(self, instance=None, owner=None):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
raise AttributeError(
|
return self
|
||||||
"The '%s' attribute can only be accessed from %s instances."
|
|
||||||
% (self.field.name, owner.__name__))
|
|
||||||
|
|
||||||
# This is slightly complicated, so worth an explanation.
|
# This is slightly complicated, so worth an explanation.
|
||||||
# instance.file`needs to ultimately return some instance of `File`,
|
# instance.file`needs to ultimately return some instance of `File`,
|
||||||
|
|
|
@ -18,6 +18,7 @@ from django.core.files.storage import FileSystemStorage, get_storage_class
|
||||||
from django.core.files.uploadedfile import (
|
from django.core.files.uploadedfile import (
|
||||||
InMemoryUploadedFile, SimpleUploadedFile, TemporaryUploadedFile,
|
InMemoryUploadedFile, SimpleUploadedFile, TemporaryUploadedFile,
|
||||||
)
|
)
|
||||||
|
from django.db.models.fields.files import FileDescriptor
|
||||||
from django.test import (
|
from django.test import (
|
||||||
LiveServerTestCase, SimpleTestCase, TestCase, override_settings,
|
LiveServerTestCase, SimpleTestCase, TestCase, override_settings,
|
||||||
)
|
)
|
||||||
|
@ -447,9 +448,7 @@ class FileFieldStorageTests(TestCase):
|
||||||
return 255 # Should be safe on most backends
|
return 255 # Should be safe on most backends
|
||||||
|
|
||||||
def test_files(self):
|
def test_files(self):
|
||||||
# Attempting to access a FileField from the class raises a descriptive
|
self.assertIsInstance(Storage.normal, FileDescriptor)
|
||||||
# error
|
|
||||||
self.assertRaises(AttributeError, lambda: Storage.normal)
|
|
||||||
|
|
||||||
# An object without a file has limited functionality.
|
# An object without a file has limited functionality.
|
||||||
obj1 = Storage()
|
obj1 = Storage()
|
||||||
|
|
Loading…
Reference in New Issue