class DjangoJSONEncoder(json.JSONEncoder):
...
elif isinstance(o, (decimal.Decimal, uuid.UUID, Promise)):
return str(o)
...
def _value_from_field(self, obj, field):
value = field.value_from_object(obj)
# Protected types (i.e., primitives like None, numbers, dates,
# and Decimals) are passed through as is. All other values are
# converted to string first.
return value if is_protected_type(value) else field.value_to_string(obj)