JSON serialization of Google App Engine models

后端 未结 14 2113
不知归路
不知归路 2020-12-04 04:59

I\'ve been searching for quite a while with no success. My project isn\'t using Django, is there a simple way to serialize App Engine models (google.appengine.ext.db.Model)

14条回答
  •  隐瞒了意图╮
    2020-12-04 05:43

    Mtgred's answer above worked wonderfully for me -- I slightly modified it so I could also get the key for the entry. Not as few lines of code, but it gives me the unique key:

    class DictModel(db.Model):
    def to_dict(self):
        tempdict1 = dict([(p, unicode(getattr(self, p))) for p in self.properties()])
        tempdict2 = {'key':unicode(self.key())}
        tempdict1.update(tempdict2)
        return tempdict1
    

提交回复
热议问题