Django:如何将自定义字段序列化到fixture中并将其加载回
我有一个自定义字段,使用to_python和get_db_prep_value方法,定义如下:Django:如何将自定义字段序列化到fixture中并将其加载回,django,serialization,fixtures,custom-fields,Django,Serialization,Fixtures,Custom Fields,我有一个自定义字段,使用to_python和get_db_prep_value方法,定义如下: def to_python(self, value): if not value: return None if isinstance(value, oauth2client.client.Credentials): return value return pickle.loads(base64.b64decode(value)) def ge
def to_python(self, value):
if not value:
return None
if isinstance(value, oauth2client.client.Credentials):
return value
return pickle.loads(base64.b64decode(value))
def get_db_prep_value(self, value, connection, prepared=False):
return base64.b64encode(pickle.dumps(value))
使用dumpdata转储此字段时,值显示为:
"<oauth2client.client.OAuth2Credentials object at XXXXXXXX"
“为字段定义值到字符串的方法