Vinodh
Vinodh

Reputation: 1129

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 beginner. 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.

Upvotes: 1

Views: 111

Answers (1)

ryan
ryan

Reputation: 2955

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.

Upvotes: 1

Related Questions