开发者

Select _Key_ in google appengine

I have this model

from google.appengine.ext import db

class Question(db.Model):
    Qtitle = db.StringProperty()

Q= FirstModel(Qtitle="Who is the most handsome actor?")
Q.put()

Then I run this GQL query:

query = db.GqlQuery("SELECT __key__ FROM First开发者_如何转开发Model Qtitle='Who is the most handsome actor?' ")
results = query.fetch(10)

for result in results:
   print result

But got error!


I see two errors:

  1. Model class name is Question and not FirstModel.
  2. You missed the WHERE clause in your query.


Try this , or something like that

from google.appengine.ext import db

    class Question(db.Model):
        Qtitle = db.StringProperty()

    Q= Question(Qtitle="Who is the most handsome actor?")
    Q.put()

    query = db.GqlQuery('SELECT __key__ FROM Question where Qtitle = :qes' , qes='Who is the most handsome actor?').fetch(1)
                  for result in query
                    print result
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜