I have a model with description field, this field can be html code, for security reasons I want to create a custom field to clear this code before saving to db.
I trying to use the lib bleach https://github.com/mozilla/bleach, but i don't know if I'm doing it right
this my customField
class HtmlField(models.TextField):
description = 'Clean HTML field'
def __init__(self, *args, **kwargs):
bleach.clean(self.description)
super().__init__(*args, **kwargs)
EDIT:
I can save the data the way I want, but I reebo this error not migrate: TypeError: argument cannot be of 'NoneType' type, must be of text type
EDIT2: I solved the previous problem by placing a check if the text is empty:
if not value:
return ''