开发者

How to fetch the datastore(app engine) record without instantiating a model?

Hi can anyone tell me how it can be done,i am a beg开发者_如何转开发inner. I tried using this:

def get_entities(keys):
    rpc = datastore.GetRpcFromKwargs({})
    keys, multiple = datastore.NormalizeAndTypeCheckKeys(keys)
    entities = None
    try:
        entities = datastore.Get(keys, rpc=rpc)
    except datastore_errors.EntityNotFoundError:
        assert not multiple

    return entities 

but unable to get keys without the models use.


do you mean you want datastore.Entity objects instead of Model instances? if so, assuming keys is a list, you should be able to simplify your code to this:

return datastore.Get(keys)

otherwise, if you just want to see which keys have matching entities in the datastore, try this:

return db.GqlQuery('SELECT __key__ FROM <kind> WHERE __key__ IN :1', keys)

replace <kind> with the kind of entity you're querying for.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜