mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Support empty file fields
This commit is contained in:
parent
4c015df28c
commit
5ead8dc89d
|
@ -913,6 +913,8 @@ class FileField(Field):
|
|||
|
||||
def to_representation(self, value):
|
||||
if self.use_url:
|
||||
if not value:
|
||||
return None
|
||||
url = settings.MEDIA_URL + value.url
|
||||
request = self.context.get('request', None)
|
||||
if request is not None:
|
||||
|
|
|
@ -879,7 +879,8 @@ class TestFileField(FieldValues):
|
|||
(MockFile(name='x' * 100, size=10), ['Ensure this filename has at most 10 characters (it has 100).'])
|
||||
]
|
||||
outputs = [
|
||||
(MockFile(name='example.txt', url='/example.txt'), '/example.txt')
|
||||
(MockFile(name='example.txt', url='/example.txt'), '/example.txt'),
|
||||
('', None)
|
||||
]
|
||||
field = fields.FileField(max_length=10)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user