class HTMLFormField(forms.CharField):
"""An html form field that handles the processing of html content from
forms."""
def to_python(self, value):
if value:
value = sanitize_html(clean_html(value))
return super(HTMLFormField, self).to_python(value)
HTMLModelField
class HTMLField(with_metaclass(models.SubfieldBase, models.TextField)):
"""Model field that stores html."""
def formfield(self, **kwargs):
defaults = {'form_class': HTMLFormField}
defaults.update(kwargs)
return super(HTMLField, self).formfield(**defaults)
This code isn't fully tested, but I think that's all it would take.
That's good pragmatic thinking. :+1: If we'd also add a CSS class to the output, the JavaScript code could automatically change the fields into a WYSIWYG area.
The code is rather simple:
HTMLFormField
HTMLModelField
This code isn't fully tested, but I think that's all it would take.