mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Unsaved file objects may not have an associated URL.
This commit is contained in:
parent
9b8f966e06
commit
321133242f
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user