我正在使用 Danny Hermes 为 Google App Engine 创建的 Endpoints-proto-datastore。
我的模型看起来像这样:
class Datum(EndpointsModel):
year = ndb.IntegerProperty(required=True)
value = ndb.FloatProperty(required=True)
class Variable(EndpointsModel):
name = ndb.StringProperty(required=True)
data = ndb.StructuredProperty(Datum, repeated=True)
class Indicator(EndpointsModel):
name = ndb.StringProperty(required=True)
variables = ndb.KeyProperty(kind=Variable, repeated=True)
formula = ndb.StringProperty(required=True)
我的 API 是这样的:
@endpoints.api(name="SomeAPI", version="v1", description="someDescription")
class SomeAPI(remote.Service):
@Indicator.query_method(query_fields=("limit", "pageToken"),
name="indicator.list",
path="indicators")
def list_indicators(self, query):
return query
问题是当我提出请求时,我得到
{
"items": [
{
"name": "IndicatorName",
"variables": [
"agtkZXZ-bW9uaXRvcnITCxIIVmFyaWFibGUiBU1BVFJQDA",
"agtkZXZ-bW9uaXRvcnISCxIIVmFyaWFibGUiBFBST1AM"
],
"formula": "someFormula"
}
]
}
但是获取变量键对我来说并没有真正的用处,因为这会迫使客户端再次请求指标实体上的变量。我想获取变量内容,如下所示:
{
"items": [
{
"name": "IndicatorName",
"variables": [
{
"name": "some Variable",
"data": [
{
"value": 230,
"year": 2000,
},
{
"value": 250,
"year": 2005,
}
]
},
{
"name": "some other Variable",
"data": [
{
"value": 230,
"year": 2000,
},
{
"value": 250,
"year": 2005,
},
{
"value": 260,
"year": 2010,
}
]
}
],
"formula": "someFormula"
}
]
}