开发者

How to retrieve entity from key value in GQL

I am using Google App Eng开发者_开发技巧ine'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?


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)


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜