The to-do list controller

Now that we have gone through the basics, let's work on our Todo Task list. We want to have a /todos URL showing us a web page with a list of Todo Tasks.

For that, we need a controller method to prepare the data to present, and a QWeb template to present it to the user.

Edit the todo_website/controllers/main.py file to add this method:

#class Todo(http.Controller): 
#...
    @http.route('/todos', auth='user', website=True) 
    def index(self, **kwargs): 
        TodoTask = request.env['todo.task'] 
        tasks = TodoTask.search([]) 
        return request.render( 
            'todo_website.index',            {'tasks': tasks}) 

The controller retrieves the data to be used and makes it available to the rendered template. In this case, the controller requires an authenticated ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.