How to do it...

To add a new Model, we need to add a Python file describing it and then upgrade the add-on module (or install it, if this was not already done). The paths that are used are relative to our add-on module's location (for example, ~/odoo-dev/local-addons/my_library/):

  1. Add a Python file to the models/library_book.py module with the following code:
from odoo import models, fields class LibraryBook(models.Model): _name = 'library.book' name = fields.Char('Title', required=True) date_release = fields.Date('Release Date')
author_ids = fields.Many2many(
'res.partner',
string='Authors'
)
  1. Add a Python initialization file with code files to be loaded by the models/__init__.py module with the following code:
from . import library_book 
  1. Edit the module Python initialization file to have the models/ directory loaded by the module:
from . import models

  1. Upgrade the Odoo module either from the command line or from the Apps menu in the user interface. If you look closely at the server log while upgrading the module, you should see the following line:
odoo.modules.registry: module my_library: creating or updating database table

After this, the new library.book model should be available in our Odoo instance. There are two ways to check whether our model has been added to the database or not.

First, you can check it in the Odoo user interface. Activate the developer tools and open the menu at Settings|Technical|Database Structure|Models. Search for the library.book model here.

The second way is to check the table entry in your PostgreSQL database. You can search for the library_book table in the database. In the following code example, we used the test-12.0 database. However, you can replace this with your database name:

$ psql test-12.0
test-12.0# d library_book;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset