我有一个简单的 NDB 模型:
from google.appengine.ext import ndb
import logging
from libs import Api
class User(ndb.Model):
oauth_token = ndb.StringProperty(required=False, indexed=False)
@classmethod
def update_data(self):
logging.info("uid = %s, oauth token = %s" % (self.key, self.oauth_token))
api = Api.Init(self.oauth_token)
在一个单独的文件test.py
中,我有以下代码:
from models import User
from google.appengine.ext import webapp, ndb
import logging
class Test(webapp.RequestHandler):
def get(self):
uid = 1
u = ndb.Key(User, str(uid)).get()
logging.info("uid = %s, oauth token = %s" % (u.key.string_id(), u.oauth_token))
u.update_data()
这是日志中的输出:
INFO 2012-07-22 16:32:42,532 test.py:8] uid = Key('User', '1'), oauth token = xxxxxxxxxxxxxxxxxxx
INFO 2012-07-22 16:32:42,532 user.py:9] uid = ModelKey('__key__'), oath token = StringProperty('oauth_token', indexed=False)
为什么我得到StringProperty('oauth_token', indexed=False)
的不是实际财产的价值?