How to retrieve entity from key value in GQL

2.4k Views Asked by At

I am using Google App Engine's datastore and wants to retrieve an entity whose key value is written as

ID/Name

id=1

Can anyone suggest me a GQL query to view that entity in datastore admin console and also in my python program?

2

There are 2 best solutions below

0
On BEST ANSWER

From your application use the get_by_id() class method of the Model:

entity = YourModel.get_by_id(1)

From Datastore viewer you should use the KEY function:

SELECT * FROM YourModel WHERE __key__ = KEY('YourModel',1)
1
On

An application can retrieve a model instance for a given Key using the get() function.

class member(db.Model):
    firstName=db.StringProperty(verbose_name='First Name',required=False)
    lastName=db.StringProperty(verbose_name='Last Name',required=False)

...

id = int(self.request.get('id'))
entity= member.get(db.Key.from_path('member', id))

I'm not sure how to return a specific entity in the admin console.