Creating fields
After creating a new model, the next step is to add fields to it. Odoo supports all the basic data types expected, such as text strings, integers, floating point numbers, Booleans, dates, date-times, and image or binary data.
Let's explore the several types of field available in Odoo.
Basic field types
We will revisit the book model to present the several field types available. We should edit the library_app/models/library_book.py
file and edit the Book
class to look like this:
# class Book(models.Model): # ... # String fields: name = fields.Char('Title') isbn = fields.Char('ISBN') book_type = fields.Selection( [('paper','Paperback'), ('hard','Hardcover'), ('electronic','Electronic'), ('other', 'Other')], 'Type') notes = fields.Text('Internal Notes') descr = fields.Html('Description') # Numeric fields: copies = fields.Integer(default=1) avg_rating = fields.Float('Average Rating', (3, 2)) price = fields...