import re
from rest_framework.fields import CharField
class UeditorField(CharField):
def to_representation(self, value):
text = super(UeditorField, self).to_representation(value)
urls = re.findall(r'src="(.*?)"', text)
request = self.context.get('request', None)
if request is not None:
urls = [request.build_absolute_uri(i) for i in urls]
text = re.sub(r'src="(.*?)"', 'src="{}"', text)
text = text.format(*urls)
return text