我在表单中创建了一个带有聊天功能的自定义模块。
我想发布自定义消息。但我收到以下错误。
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
我的 .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)
尝试将其导入您的 .py 文件
来自 openerp 导入工具
从 openerp.tools.translate 导入 _
_ 用于在事件用户的语言根据更改时翻译消息。它翻译您的 .po 文件中的消息。
我是一名优秀的程序员,十分优秀!