如何实现向字段写入序列号
-
各位前辈,我照着官方文档做demo的时候,想向[font=verdana][size=2px]Course类[/size][/font]中添加课程代码,但是添加后一直报错,希望各位前辈能帮帮我。拜谢!!
class Course(models.Model):
"""docstring for Course"""
_name = 'openacademy.course'
name = fields.Char(string=u'课程名称', required=True)
description = fields.Text(string=u'描述')
responsible_id = fields.Many2one('res.users', ondelete='set null', string=u'负责人', index=True)
session_ids = fields.One2many('openacademy.session', 'course_id', string=u'课程安排')
courseNo = fields.Char(string=u'课程代码', readonly=True)
_sql_constraints = [
('name_description_check',
'CHECK(name != description)',
u"课程的名称不应该描述"),
('name_unique',
'UNIQUE(name)',
u"课程名称必须是唯一的"),
]
def create(self, cr, uid, vals, context=None):
vals['courseNo'] = self.pool.get('ir.sequence').get(cr, uid, 'openacademy.course')
return super(openacademy.course, self).create(cr, uid, vals, context=context) -
[quote]super(openacademy.course, self)[/quote]
应该是super(Course, self)
-
感谢digitalsatori的指点,我已经解决这个问题了,并成功生成课程代码,下面吧代码贴出来供有需要的小伙伴查考。
<br /> courseNo = fields.Char(string=u'课程代码', readonly=True)<br /><br /> @api.model<br /> def create(self, vals):<br /> vals['courseNo'] = self.pool.get('ir.sequence').get(self.env.cr, self.env.uid, 'Course')<br /> return super(Course, self).create(vals)<br />