我有来自Endpoints Proto Datastore API的EndpointsModel,名为Resource,我正在使用:Resource.query()。fetch(10)请求10个项目。
问题是它返回了一个资源数组,但是根据“创建端点API”的文档,我需要返回一组消息。
https://cloud.google.com/appengine/docs/python/endpoints/create_api
Proto RPC messages with Google Cloud Enpoints
有没有一种标准方法可以将我的模型数组转换为消息,或者for循环是最有效的方法吗?
提前致谢!
答案 0 :(得分:0)
I did a bit more digging and I found an example by Google Cloud Platform on GitHub ( https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-python ). tictactoe_api.py uses a for loop on the returning NDB values and a custom to_message() function in models.py to convert them to a protoRPC message.