JSON serialization of Google App Engine models

后端 未结 14 2117
不知归路
不知归路 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:52

    There's a method, "Model.properties()", defined for all Model classes. It returns the dict you seek.

    from django.utils import simplejson
    class Photo(db.Model):
      # ...
    
    my_photo = Photo(...)
    simplejson.dumps(my_photo.properties())
    

    See Model properties in the docs.

提交回复
热议问题