需求:获取项目阶段列表
实现方法:
<ul>
<li>在controller添加一个test方法, 不需参数
<pre><code>```
@http.route('/test', type = 'json', auth = 'public')
def test(self):
phases = http.request.env['project.task.type'].search([])
list = []
dic = {}
for phase in phases:
list.append(phase.name)
dic['phases'] = list
return json.dumps(dic)
<b>注意:project.task.type 这个model需要设置为公开的群组访问控制</b>
</li>
<li>打开终端:
curl 'http://localhost:8069/test' -H 'Content-Type: application/json' --data "{}"
</li>
<li>结果如下:
![jsonrpc](http://upload-images.jianshu.io/upload_images/143568-b2b00c57fe1148af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
</li>
</ul>