我想在谷歌的数据存储中存储位置。每个条目都应具有“sys”字段,其中应包含数据存储设置的信息。我有下面的类模型,WebService JSON 请求/响应看起来不错,但我必须手动设置值。它看起来像,auto_current_user_add
并且不会触发。auto_now_add
auto_current_user
auto_now
from google.appengine.ext import ndb
from endpoints_proto_datastore.ndb import EndpointsModel
class Created(EndpointsModel):
by = ndb.UserProperty(auto_current_user_add=True)
on = ndb.DateTimeProperty(auto_now_add=True)
class Updated(EndpointsModel):
by = ndb.UserProperty(auto_current_user=True)
on = ndb.DateTimeProperty(auto_now=True)
class Sys(EndpointsModel):
created = ndb.StructuredProperty(Created)
updated = ndb.StructuredProperty(Updated)
class Location(EndpointsModel):
name = ndb.StringProperty(required=True)
description = ndb.TextProperty()
address = ndb.StringProperty()
sys = ndb.StructuredProperty(Sys)
当我提交创建请求 ( location.put()
) 时,我收到以下响应:
{
"id": "4020001",
"name": "asdf"
}
当我使用手动设置它时:
location.sys = Sys(created=Created(on=datetime.datetime.now(),
by=current_user),
updated=Updated(on=datetime.datetime.now(),
by=current_user))
location.put()
我得到了预期的结果:
{
"id": "4020002",
"name": "asdf",
"sys": {
"created": {
"by": {
"auth_domain": "gmail.com",
"email": "decurgia@XYZ"
},
"on": "2015-01-27T16:05:41.465497"
},
"updated": {
"by": {
"auth_domain": "gmail.com",
"email": "decurgia@XYZ"
},
"on": "2015-01-27T16:05:41.465577"
}
}
}
如何自动设置这些字段( sys.created.on
, sys.created.by
, sys.updated.on
, )?sys.updated.by