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.
精彩评论