mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-03 05:04:31 +03:00
Avoided double call for remote url in FileField.to_representation. (#6841)
This commit is contained in:
parent
0cc09f0c0d
commit
7e1c4be7ce
|
@ -1546,16 +1546,16 @@ class FileField(Field):
|
|||
return None
|
||||
|
||||
use_url = getattr(self, 'use_url', api_settings.UPLOADED_FILES_USE_URL)
|
||||
|
||||
if use_url:
|
||||
if not getattr(value, 'url', None):
|
||||
# If the file has not been saved it may not have a URL.
|
||||
try:
|
||||
url = value.url
|
||||
except AttributeError:
|
||||
return None
|
||||
url = value.url
|
||||
request = self.context.get('request', None)
|
||||
if request is not None:
|
||||
return request.build_absolute_uri(url)
|
||||
return url
|
||||
|
||||
return value.name
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user