AppEngine bulkloader export Model with self-defined Property

回眸只為那壹抹淺笑 提交于 2019-12-04 17:43:22

Okay I'm answering my own questions...

I still don't know why pickle doesn't work, but after changing to use simplejson instead of pickle, I can successfully export MyProperty in the designated format.

The bulkloader.yaml may look like this.

python_preamable:
- import myutils
- import django.utils.simplejson
...

transformers:
- kind: MyModel
  connector: csv
  property_map:
  ...
  - property: info
    external_name: info
    export_transform: myutils.load_info

And in myutils.py load_info may look like this.

def load_info():
    def load(x):
        if not x:
            return ''
        info = simplejson.loads(x)
        return '%s-%s' % (info['id'], info['name']) # the output format for info
    return load
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!