mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Merge pull request #3074 from tomchristie/unsaved_file_objects_serialize_to_none
Unsaved file objects may not have an associated URL.
This commit is contained in:
commit
cd0c9b7555
|
@ -1198,8 +1198,12 @@ class FileField(Field):
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user