在google appengine中选择_Key_

时间:2011-09-09 05:39:20

标签: google-app-engine gql

我有这个模型

from google.appengine.ext import db

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

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

然后我运行这个GQL查询:

query = db.GqlQuery("SELECT __key__ FROM FirstModel Qtitle='Who is the most handsome actor?' ")
results = query.fetch(10)

for result in results:
   print result

但得到了错误!

2 个答案:

答案 0 :(得分:1)

我看到两个错误:

  1. 模型类名称为Question,而非FirstModel
  2. 您错过了查询中的WHERE子句。

答案 1 :(得分:1)

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