Exposing related fields stored in other models
When reading data from the server, Odoo clients can only get values for the fields that are available in the model and being queried. Client-side code, unlike server-side code, can't use dot notation to access data in the related tables.
However, these 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 Books
model.
Getting ready
We will continue using the my_library
add-on module from the previous recipe.
How to do it...
Edit the models/library_book.py
file to add the new related
field:
- Ensure that we have a field for the book publisher:
class LibraryBook(models.Model): # ... publisher_id = fields.Many2one( 'res.partner', string='Publisher')
- Now, add the related field for the publisher's city...