O'Reilly logo

Odoo Development Cookbook by Daniel Reis, Alexandre Fayolle, Holger Brunn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exposing Related fields stored in other models

When reading data from the server, Odoo clients can only get values for the fields available in the model being queried. Client-side code can't use dot notation to access data in the related tables like server-side code can.

But those fields can be made available there by adding them as related fields. We will do this to make the publisher's city available in the Library Book model.

Getting ready

We will reuse the my_module addon module from Chapter 3, Create Odoo Modules.

How to do it…

Edit the models/library_book.py file to add the new "related" field:

  1. Make sure that we have a field for the book Publisher:
    class LibraryBook(models.Model): # ... publisher_id = fields.Many2one( 'res.partner', string='Publisher') ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required