开发者

What's the correct way to store an object in a Model property?

I need to store a Django template object in a Model property.

My solution so far has been to pickle the object before assigning it to a BlobProperty :

entity.template_blob = pickle.dumps(template)
entity.put()

And then after a fetch from the datastore, I do :

template = pickle.loads(entity.template_bl开发者_如何学JAVAob)

Am I doing this wrong ? I couldn't find a property suited to the storage of any object.


You've got it right. Pickling to a blob is the standard solution for this problem.

There isn't a built-in property that automatically handles the serialization / deserialization, but the PickleProperty in aetycoon will do this for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜