开发者

Select _Key_ in google appengine

开发者 https://www.devze.com 2023-04-03 13:06 出处:网络
I have this model from google.appengine.ext import db class Question(db.Model): Qtitle = db.StringProperty()

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

精彩评论

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