星辉Odoo模型开发教程3-创建字段

创建新模型后的第一步是添加字段。 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值