I get this error when I want to test my code using factory-boy:
AttributeError: 'str' object has no attribute 'raw'. See also this question on stackoverflow.
Therefore I have to subclass the MarkupField:
from markitup.fields import render_func, _rendered_field_name
class MyMarkupField(MarkupField):
def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
if hasattr(value, "raw"):
return value.raw
return value
def pre_save(self, model_instance, add):
value = super(MarkupField, self).pre_save(model_instance, add)
if hasattr(value, "raw"):
value = value.raw
elif value is None:
value = ''
rendered = render_func(value)
setattr(model_instance, _rendered_field_name(self.attname), rendered)
return value
I get this error when I want to test my code using factory-boy:
AttributeError: 'str' object has no attribute 'raw'
. See also this question on stackoverflow.Therefore I have to subclass the
MarkupField
:This isn't ideal. Can we fix this, please?