mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Update fields.py
ImageFields can show_urls=True instead of file names
This commit is contained in:
parent
1e9ea377e3
commit
aa5809d1b7
|
@ -988,6 +988,15 @@ class ImageField(FileField):
|
||||||
'invalid_image': _("Upload a valid image. The file you uploaded was "
|
'invalid_image': _("Upload a valid image. The file you uploaded was "
|
||||||
"either not an image or a corrupted image."),
|
"either not an image or a corrupted image."),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.show_url = kwargs.pop('show_url', False)
|
||||||
|
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):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user