Adding data fields to a model
A field represents a column in a database table and defines the structure of the data that can be stored in that column. Fields in Odoo models are used to specify the attributes and characteristics of the data that the model will store. Each field has a data type (e.g., Char
, Integer
, Float
, or Date
) and various attributes that determine how the field behaves.
In this section, you will explore the various data types that fields can support and how to add them to a model.
Getting ready
This recipe assumes that you have an instance ready with the my_hostel
add-on module available, as described in Chapter 3, Creating Odoo Add-On Modules.
How to do it...
The my_hostel
add-on module should already have models/hostel.py
, defining a basic model. We will edit it to add new fields:
- Use the minimal syntax to add fields to the
Hostel
model:from odoo import models, fields class Hostel(models.Model): # … ...