Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to retrieve existing model data and display on a custom odoo website

By
Boniface Irungu
on 11/18/15, 11:19 AM 752 views

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.

1
Boniface Irungu
On 11/18/15, 11:37 AM

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


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/18/15, 11:19 AM
Seen: 752 times
Last updated: 11/19/15, 3:19 AM