Commit cd0c9b75 by Tom Christie

Merge pull request #3074 from tomchristie/unsaved_file_objects_serialize_to_none

Unsaved file objects may not have an associated URL.
parents 9b8f966e 32113324
......@@ -1198,9 +1198,13 @@ class FileField(Field):
return data
def to_representation(self, value):
if self.use_url:
if not value:
return None
if self.use_url:
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)
if request is not None:
......
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