Unsaved file objects may not have an associated URL.

This commit is contained in:
Tom Christie 2015-06-24 14:24:19 +01:00
parent 9b8f966e06
commit 321133242f

View File

@ -1198,8 +1198,12 @@ class FileField(Field):
return data
def to_representation(self, value):
if not value:
return None
if self.use_url:
if not value:
if not getattr(value, 'url', None):
# If the file has not been saved it may not have a URL.
return None
url = value.url
request = self.context.get('request', None)