name = fields.Char(string='单据编号',required=True)
note = fields.Text(string='备注', tracking=True)
active = fields.Boolean(default=True, string='是否归档', tracking=True)
sequence = fields.Integer(string='排序', default=50)
price_unit = fields.Float(string='单价',default=0.0,digits='Product Price')
date = fields.Date(string='截止日期', tracking=True, default=fields.Date.today)
小贴示:
static today() – 以ORM期望的格式返回当前日期
static context_today() – 返回一个客户端时区的当前日期,可以接收一个datetime格式的参数
static to_date() – 将一个值转换成date对象
static to_string() – 将一个date或datetime对象转换成string
top_time = fields.Datetime(string='置顶', default=fields.Datetime.now())
today = datetime.date.today() - datetime.timedelta(days=3)
date = datetime.datetime.strptime(kw[key], '%Y-%m-%d %H:%M:%S')
小贴示:
static add – 添加一个值
static context_timestamp
static now – 以ORM期望的格式返回当前日期和时间
static to_datetime()
static to_string()
static today()
files = fields.Binary(string='文件', filters='*.xlsx', required=True)
简版格式:
快捷键:
| required | 字段必填,这通过在数据库层面为列添加NOT NULL 约束来实现。 |
|---|---|
| readonly | 字段只读,在 API 层面并没有强制,模型方法中的代码仍然可以向其写入。仅针对用户界面设置。 |
| invisible | 隐藏 |
| index | 索引,为字段添加数据库索引,让搜索更快速,但同时也会部分降低写操作速度,默认为False。 |
| help | 帮助文本:可以当前字段的用途,注意事项等 |
price_subtotal = fields.Monetary(compute='_compute_amount', string='小计', readonly=True)
article = fields.Html(string='文章')