开发者

Turn Google App Engine GqlQuery result into a Python dictionary

H开发者_如何转开发ow to turn an app engine GqlQuery into a dictionary, so that i can modify it, before turn it into JSON string?

Regards,

Johnny

p.s. I know there's a similar post, but the link suggested doesn't open any more.


entities = YourKind.all().fetch(20)

dict_of_entities = dict((str(entity.key()), {'name': entity.name, 'size': entity.size}) for entity in entities)

# or

list_of_entities = [{'key': str(entity.key()),
                     'name': entity.name,
                     'size': entity.size} for entity in entities)]


You can use the low-level datastore interface found in google.appengine.api.datastore (and documented there, too). This provides an interface to the datastore that lets you work with dictionaries instead of models.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜