Python openerp消息发布错误..NameError:全局名称'_';没有定义

Python openerp消息发布错误..NameError:全局名称'_';没有定义,python,openerp,Python,Openerp,我已经在表单中创建了一个带有chatter的自定义模块 我想发布一条自定义消息。但我得到以下错误 File "/opt/openerp/my_modules/forum/forum.py", line 22, in function_which_post_msg self.message_post(cr, uid, ids, body=_("New Question has been <b>created</b>"), context=context) NameE

我已经在表单中创建了一个带有chatter的自定义模块

我想发布一条自定义消息。但我得到以下错误

File "/opt/openerp/my_modules/forum/forum.py", line 22, in function_which_post_msg
    self.message_post(cr, uid, ids, body=_("New Question has been <b>created</b>"), context=context)
NameError: global name '_' is not defined
文件“/opt/openerp/my_modules/forum/forum.py”,第22行,在函数中发布消息
self.message_post(cr、uid、ids、body=_(“新问题已创建”),context=context)
NameError:未定义全局名称“\u1”
我的.py文件是

import datetime
import time
import openerp
from openerp.osv import osv, fields


class Course(osv.osv):
    _name = "forum.course"
    _inherit = ['mail.thread', 'ir.needaction_mixin']

    _columns = {
              'name' : fields.char(string="Question Title", size=256, required=True),
              'description' : fields.text(string="Question Description", required=True),

               }


    def function_which_post_msg(self, cr, uid, ids, context=None):
        self.message_post(cr, uid, ids, body=_("New Question has been <b>created</b>"), context=context)

    def create(self, cr, uid, ids, context=None):
        self.function_which_post_msg(cr, uid, ids, context=context)
导入日期时间
导入时间
导入openerp
从openerp.osv导入osv,字段
课堂课程(osv.osv):
_name=“论坛.课程”
_inherit=['mail.thread','ir.needaction\u mixin']
_列={
“name”:fields.char(string=“Question Title”,size=256,required=True),
“description”:fields.text(string=“Question description”,required=True),
}
def function_which_post_msg(self、cr、uid、ids、context=None):
self.message_post(cr、uid、ids、body=_(“新问题已创建”),context=context)
def创建(self、cr、uid、id、context=None):
self.function\u which\u post\u msg(cr、uid、ids、context=context)

尝试在.py文件中导入

来自openerp导入工具

从openerp.tools.translate导入


\u用于在活动用户的语言根据更改时翻译消息。将消息翻译为您的.po文件。

\u错误已解决,但出现以下错误。文件“/opt/openerp/my_modules/forum_nyros/forum.py”,第24行,在函数_中发布消息self.message_post(cr、uid、id、body=”(新问题已创建),context=context)文件“/opt/openerp/addons/mail/mail_thread.py”,第1023行,在消息_post“无效线程id;应为0、False、id或具有一个id的列表”中你能提出一个新问题吗?所以不要重复这个问题的标题。并接受这个答案。谢谢你把它作为新问题发布,请检查它并帮助我找到新问题链接