Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
11789 Lượt xem

Hi All ,


Am trying to retrieve project data from model project.project and display on a customized website module in odoo 8. 

So far i have the module created and installed.  See code below for what i have. 


models.py 

from openerp import models, fields, api

#Just inherit default odoo project.project fields

class project_category(models.Model):

_name='project.project'

_inherit='project.project'

controllers.py

class Website(http.Controller):
@http.route('/index',auth='public',website=True)
def list(self,**kw):
projects = http.request.env['project.project']
print "Test is below "
print projects # this prints project.project() which i think its an empty array. My goal is to retrieve projects and render them on

# template layout
return http.request.render('website.layout',
{'categories':projects.search([])
})

Any suggestions most welcomed. Thank you.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Solved this issue. I realized the array is empty because i was printing before calling search() method which performs read operations. 

On the template side templates.xml i accessed projects by

<t t-foreach="categories" t-as="category">

 <t  t-esc="category.name" />

</t>

Thanks


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 6 16
3721
2
thg 7 25
343
4
thg 6 25
632
1
thg 6 25
897
1
thg 5 25
948