0
與關鍵讀書,我在谷歌應用程序引擎Python的 - 在App Engine中
有一個Python程序當發現在數據存儲中的對象時,我有鑰匙作爲一個字符串,我該怎麼辦直接讀取。下面是我的代碼正在執行一個循環,不好.....
class Opportunity(db.Model):
customer = db.ReferenceProperty(Customer,collection_name='opportunitys')
BNusername = db.StringProperty()
opportunity_no = db.StringProperty()
# etc etc etc.....
#BnPresets holds the object key as a string
opportunitys = Opportunity.all()
opportunitys.filter('BNusername =',BnPresets.myusername)
for oprec in opportunitys:
if str(oprec.key()) == BnPresets.recordkey:
opportunity = oprec
# I have the object here and can process etc etc
我猜測opportunity = db.get(opportunity_key)進入類Opportunity(db.Model):部分。這意味着當我執行db.get時,我總是使用相同的變量來保存KEY。我還假設機會= Opportunity.all()等代碼將工作,當我想獲得幾個對象。我有這個權利嗎? –
請注意,db.get也將直接在密鑰的字符串表示形式上工作。您可以跳過第一步,然後執行opportunity = db.get(BnPresets.recordkey)。 –