Franck
Franck

Reputation: 6325

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_blob)

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

Upvotes: 0

Views: 86

Answers (1)

Drew Sears
Drew Sears

Reputation: 12838

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.

Upvotes: 3

Related Questions