Adding data fields to a model
Models are meant to store data, and this data is structured in fields. Here, you will learn about the several types of data that can be stored in fields, and how to add them to a model.
Getting ready
This recipe assumes that you have an instance ready with the my_library
add-on module available, as described in Chapter 3, Creating Odoo Add-On Modules.
How to do it...
The my_library
add-on module should already have models/library_book.py
, defining a basic model. We will edit it to add new fields:
- Use the minimal syntax to add fields to the
Library Books
model:from odoo import models, fields class LibraryBook(models.Model): Â Â Â Â # ... Â Â Â Â short_name = fields.Char('Short Title') Â Â Â Â notes = fields.Text('Internal Notes') Â Â Â Â state = fields.Selection( Â Â Â Â Â Â Â Â [('draft', 'Not Available...