Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Unsaved file objects may not have an associated URL.
  • Loading branch information
lovelydinosaur committed Jun 24, 2015
commit 321133242f40e18b3d7564a43a3b515c17f3e40c
6 changes: 5 additions & 1 deletion rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,12 @@ def to_internal_value(self, data):
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)
Expand Down