views:

205

answers:

1

I'm building an AppEngine model class. I need a simple list of tuples:

class MyTuple(object):
  field1 = "string"
  field2 = 3

class MyModel(db.Model):
  the_list = db.ListProperty(MyTuple)

This does not work, since AppEngine does not accept MyTuple as a valid field.

Solutions I can think of:

  1. Make MyTuple extend db.Model. But doesn't that mean every entry in the list will be stored in a dedicated MyTuple table?

  2. Make it a list of strings, which are a "serialized" form of MyTuple; add parsing (unserializing) code. Yuck.

  3. Maintain two lists (one of strings, one of ints). Another yuck.

Any other solution that I'm missing?

+1  A: 

In app-engine-patch there's a FakeModelListProperty and FakeModel (import both from ragendja.dbutils). Derive MyTuple from FakeModel and set fields = ('field1', 'field2'). Those fields will automatically get converted to JSON when stored in the list, so you could manually edit them in a textarea. Of course, this only works for primitive types (strings, integers, etc.). Take a look at the source if this doesn't suffice.

http://code.google.com/p/app-engine-patch/