Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django:如何将自定义字段序列化到fixture中并将其加载回_Django_Serialization_Fixtures_Custom Fields - Fatal编程技术网

Django:如何将自定义字段序列化到fixture中并将其加载回

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

我有一个自定义字段,使用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 get_db_prep_value(self, value, connection, prepared=False):
    return base64.b64encode(pickle.dumps(value))
使用dumpdata转储此字段时,值显示为:

"<oauth2client.client.OAuth2Credentials object at XXXXXXXX"

“为字段定义
值到字符串的方法