Google App Engine: Saving a list of objects?

1.5k Views Asked by At

I need to save in my model a list of objects from a certain class on the datastore.

Is there any simple way to archive this with ListProperty and custom property's without going into pickled/simplejson blob data?

I just want something like this:

class Test:
     pass

class model(db.Model):
     list = db.ListProperty(Test)

Looking at GAE documentation I can't really tell if this is impossible with the current version or not.

I was trying to avoid pickling because it's slow and has size limits.

3

There are 3 best solutions below

0
On BEST ANSWER

You can only store a limited set of types directly in the datastore. To store your own types, you need to convert them into one of the accepted types in some manner - pickling is one common approach, as is serializing it as JSON.

The size limit isn't unique to pickling - 1MB is the largest Entity you can insert regardless of the fields and types.

0
On

You could save your Test objects in the datastore directly, by making a Test model/entity type. Otherwise you will have to serialize them somehow (using something like pickle or json)

0
On

You could have a list of keys or you could give 'Test' entities a parent that is a entity of your 'model' class