创建新模型后的第一步是添加字段。 Odoo 支持我们能想到的所有基本数据类型,如文本字符串、整型、浮点型、布尔型、日期、日期时间以及图片或二进制数据。下面就来看看 Odoo 中一
些可用的字段类型吧。
基本字段类型
我们将为图书模型添加几种可用的字段类型,编辑 library_app/models/library_book.py 文件后 Book 类会长这样:
class Book(models.Model):
…
String fields
name = fields.Char(‘Title’, required=True)
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.Monetary(‘Price’, ‘currency_id’)
currency_id = fields.Many2one(‘res.currency’) # price helper