我需要检查数据存储区,如果实体类型" Kayit"存在创造新的。 我的db.model类:
class Kayit(db.Model):
url=db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
目前正在使用它进行检查,但它看起来并不优雅
class MainPage(webapp2.RequestHandler):
def get(self):
r_name="none"
q=db.Query(Kayit)
try:
self.response.write(q[0].url)
except:
kay=Kayit(parent=_DefterKey(r_name),key_name='alibaba')
kay.url="some url"
kay.put()
我想我们用db.Key.from_path(' Kayit',1)获得父键。我该怎么用来检查它是否有实体?
答案 0 :(得分:1)
回答:
How to query parent entity from child entity in Google App Engine (Python) NDB/Datastore?
在云API中记录:
https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/Entity
...并显示在python"留言簿"谷歌示例:
https://cloud.google.com/appengine/docs/python/gettingstartedpython27/usingdatastore
看看这一节:
greetings_query = Greeting.query(
ancestor=guestbook_key(guestbook_name)).order(-Greeting.date)
greetings = greetings_query.fetch(10)