Commit 5ead8dc8 by Tom Christie

Support empty file fields

parent 4c015df2
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment