我正在尝试实现ndb模型审计,以便对属性的所有更改都存储在每个模型实例中.这是我选择实现的_pre_put_hook的代码.
def _pre_put_hook(self):
# save a history record for updates
if not (self.key is None or self.key.id() is None):
old_object = self.key.get(use_cache=True)
for attr in dir(self):
if not callable(getattr(self, attr)) and not attr.startswith("_"):
if getattr(self, attr) != getattr(old_object, attr):
logging.debug('UPDATE: {0}'.format(attr))
logging.debug('OLD: {0} NEW: {1}'.format(getattr(old_object, attr), getattr(self, attr)))
Run Code Online (Sandbox Code Playgroud)
问题是old_object总是填充有更新的self(对象)的相同值.如何在实际生成put()之前访问旧对象的属性值(_pre_put)?
(这是在github上发布的关于令人敬畏的端点 - 原型数据存储库的相同问题的副本)
我正在尝试实现我的API,以便客户端可以在api请求中传递'?fields ='url参数,然后我可以指示查询构建响应并仅返回请求的collection_fileds.
但是,我不知道如何将url参数传递给@query_method装饰器; 这是我的代码:
@Contact.query_method(query_fields=('limit', 'order', 'pageToken'),
collection_fields=('name', 'birthday'),
path='contacts',
name='contacts.list')
def contacts_list(self, query):
return query
Run Code Online (Sandbox Code Playgroud)
如何fields将请求中的参数传递给装饰器中的collection_fields = named param?
google-app-engine google-cloud-endpoints endpoints-proto-datastore