mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
allow show_url for all file fields
This commit is contained in:
parent
81d84fc897
commit
a832ae11e9
|
@ -951,6 +951,7 @@ class FileField(WritableField):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.max_length = kwargs.pop('max_length', None)
|
self.max_length = kwargs.pop('max_length', None)
|
||||||
self.allow_empty_file = kwargs.pop('allow_empty_file', False)
|
self.allow_empty_file = kwargs.pop('allow_empty_file', False)
|
||||||
|
self.show_url = kwargs.pop('show_url', False)
|
||||||
super(FileField, self).__init__(*args, **kwargs)
|
super(FileField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def from_native(self, data):
|
def from_native(self, data):
|
||||||
|
@ -975,6 +976,8 @@ class FileField(WritableField):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def to_native(self, value):
|
def to_native(self, value):
|
||||||
|
if self.show_url:
|
||||||
|
return value.url
|
||||||
return value.name
|
return value.name
|
||||||
|
|
||||||
|
|
||||||
|
@ -993,11 +996,6 @@ class ImageField(FileField):
|
||||||
self.show_url = kwargs.pop('show_url', False)
|
self.show_url = kwargs.pop('show_url', False)
|
||||||
super(ImageField, self).__init__(*args, **kwargs)
|
super(ImageField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def to_native(self, value):
|
|
||||||
if self.show_url:
|
|
||||||
return value.url
|
|
||||||
return value.name
|
|
||||||
|
|
||||||
def from_native(self, data):
|
def from_native(self, data):
|
||||||
"""
|
"""
|
||||||
Checks that the file-upload field data contains a valid image (GIF, JPG,
|
Checks that the file-upload field data contains a valid image (GIF, JPG,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user