显示字段值修改记录
效果:
myproject/my_first_app/models/course.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class Course(models.Model):
"""
课程
"""
_name = 'myproject.course'
_inherit = ['mail.thread'] # 继承mail.thread保存字段值修改记录
# track_visibility表示字段值修改时,消息日志中会自动追踪
name = fields.Char(string='课程名称', reqired=True, placeholder='填写课程名称', track_visibility='onchange')
description = fields.Text(string='Description', placeholder='填写课程描述', track_visibility='onchange')
sex = fields.Boolean(string='性别', default=True)
state = fields.Selection(
[('draft', "草稿"), ('open', "开启"), ('full', "满人"), ('cancel', "取消")], string="状态",
help="课程状态", default="draft"
)
responsible_id = fields.Many2one('res.users', ondelete='set null', string="负责人", index=True)
session_ids = fields.One2many('myproject.session', 'course_id', string="讲座")
def copy(self, default=None):
default = dict(default or {})
copied_count = self.search_count(
[('name', '=like', u"Copy of {}%".format(self.name))])
if not copied_count:
new_name = u"Copy of {}".format(self.name)
else:
new_name = u"Copy of {} ({})".format(self.name, copied_count)
default['name'] = new_name
return super(Course, self).copy(default)
_sql_constraints = [
('name_description_check',
'CHECK(name != description)',
"The title of the course should not be the description"),
('name_unique',
'UNIQUE(name)',
"The course title must be unique"),
]
@api.model
def js_test(self):
# 课程tree视图中测试按钮点击事件
print('dddddddddd')
然后在xml视图中显示message_ids
<div class="oe_chatter">
<field name="message_ids" widget="mail_thread"/>
</div>
myproject/my_first_app/views/course_views.xml:
所放位置如下:
更新模块就可以看到效果。
后记
【后记】为了让大家能够轻松学编程,我创建了一个公众号【轻松学编程】,里面有让你快速学会编程的文章,当然也有一些干货提高你的编程水平,也有一些编程项目适合做一些课程设计等课题。
也可加我微信【1257309054】,拉你进群,大家一起交流学习。
如果文章对您有帮助,请我喝杯咖啡吧!
公众号
关注我,我们一起成长~~