Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

value in pre_save and value_to_string is str using factory-boy #20

Open
yofe opened this issue Oct 2, 2017 · 0 comments
Open

value in pre_save and value_to_string is str using factory-boy #20

yofe opened this issue Oct 2, 2017 · 0 comments

Comments

@yofe
Copy link

yofe commented Oct 2, 2017

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

This isn't ideal. Can we fix this, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant