我有两个课程:GameSession 和 Location。每个 GameSession 都应该有一个 Location 集。
class Location(EndpointsModel):
_message_fields_schema = ('entityKey', 'name', 'description', 'address')
name = ndb.StringProperty(required=True)
description = ndb.TextProperty()
address = ndb.StringProperty()
class GameSession(EndpointsModel):
_message_fields_schema = ('entityKey', 'name', 'description', 'location')
name = ndb.StringProperty(required=True)
description = ndb.TextProperty()
location_key = ndb.KeyProperty(kind=Location, required=True)
def location_setter(self, value):
self.location_key = ndb.Key(urlsafe=value.entityKey)
@EndpointsAliasProperty(setter=location_setter, property_type=Location.ProtoModel())
def location(self):
return self.location_key.get()
当我尝试通过 Google 的 API Explorer 创建新的 GameSession 时,我收到以下错误消息:
Error parsing ProtoRPC request (Unable to parse request content: Message Location is missing required field name)
对 gamesession 的 POST 请求如下所示:
{
"name": "aaa",
"location": {
"entityKey": "ahRkZXZ-Z2FtZXNlc3Npb24tY29yZXIVCxIITG9jYXRpb24YgICAgIDArwoM"
}
}
如何只需要指定位置的 entityKey 来创建 GameSession 条目?我只是想存储密钥,这就是为什么我不想问名字。