I rewrited SelfModel.save() to do that.
But I feel it wasn't a good way.
So , I tried to create a CustomField to do this , but It looks like some wrong.
It can't render a hex str in my url , how can I fix it ?
should I rewrite get_db_prep_value() or get_lookups() ?
class BinaryHexField(BinaryField):
description = _("Raw binary data to hex str")
def __init__(self, *args, **kwargs):
kwargs['editable'] = True
super().__init__(*args, **kwargs)
def value_to_string(self, obj):
value = self.value_from_object(obj)
return value.hex(value)
def to_python(self, value):
if isinstance(value, str):
return bytes.fromhex(value)
return value