We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0cc09f0 commit 7e1c4beCopy full SHA for 7e1c4be
rest_framework/fields.py
@@ -1546,16 +1546,16 @@ def to_representation(self, value):
1546
return None
1547
1548
use_url = getattr(self, 'use_url', api_settings.UPLOADED_FILES_USE_URL)
1549
-
1550
if use_url:
1551
- if not getattr(value, 'url', None):
1552
- # If the file has not been saved it may not have a URL.
+ try:
+ url = value.url
+ except AttributeError:
1553
1554
- url = value.url
1555
request = self.context.get('request', None)
1556
if request is not None:
1557
return request.build_absolute_uri(url)
1558
return url
+
1559
return value.name
1560
1561
0 commit comments