Expanding on Adam's suggestion, you can push the pickling into its own Property class. Here is an example that handles validation, and converting the provided list into and out of a Blob type. The provided list can contain any data type or combination of datatypes, since it just stores a standard python list.
import pickle
class GenericListProperty(db.Property):
data_type = db.Blob
def validate(self, value):
if type(value) is not list:
raise db.BadValueError('Property %s must be a list, not %s.' % (self.name, type(value), value))
return value
def get_value_for_datastore(self, model_instance):
return db.Blob(pickle.dumps(getattr(model_instance,self.name)))
def make_value_from_datastore(self, value):
return pickle.loads(value)
You use it as you would any other property.
class ModelWithAGenericList(db.Model):
mylist = GenericListProperty()
class MainHandler(webapp.RequestHandler):
def get(self):
db.delete(ModelWithAGenericList.all())
m = ModelWithAGenericList(mylist = [[1,2,3],[4,5,6],6])
m.put()
m = ModelWithAGenericList.all().fetch(1)[0]
self.response.out.write(str(m.mylist))
# Outputs: [[1, 2, 3], [4, 5, 6], 6]