Adding models
Models define the data structures to be used by our business applications. This recipe shows how to add a basic model to a module.
We will use a simple book library example to explain this; we want a model to represent books. Each book has a name and a list of authors.
Getting ready
We should have a module to work with. If we follow the first recipe in this chapter, we will have an empty my_module
. We will use that for our explanation.
How to do it…
To add a new Model, we add a Python file describing it and then upgrade the addon module (or install it, if it was not already done). The paths used are relative to our addon module location (for example, ~/odoo-dev/local-addons/my_module/
):
- Add a Python file to the module,
models/library_book.py
, with the following code:# -*- coding: utf-8 -*- from openerp import models, fields class LibraryBook(models.Model): _name = 'library.book' name = fields.Char('Title', required=True) date_release = fields...