开发者

Turn Google App Engine GqlQuery result into a Python dictionary

开发者 https://www.devze.com 2023-01-30 23:57 出处:网络
H开发者_如何转开发ow to turn an app engine GqlQuery into a dictionary, so that i can modify it, before turn it into JSON string?

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

精彩评论

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

关注公众号