def to_native(self, value): """ Converts the field's value into it's simple representation. """ if is_simple_callable(value): value = value() if is_protected_type(value): return value elif hasattr(self, 'model_field'): return self.model_field.value_to_string(self.obj) return smart_unicode(value)
def to_native(self, obj): """ Serialize objects -> primatives. """ if _is_protected_type(obj): return obj elif is_simple_callable(obj): return self.to_native(obj()) elif isinstance(obj, dict): return dict([(key, self.to_native(val)) for (key, val) in obj.items()]) elif hasattr(obj, '__iter__'): return (self.to_native(item) for item in obj) return self.convert_object(obj)