我正在创建openerp模块,在此我收到以下错误。我创建了一个函数 我的python代码在下面。
_columns = {
'name' : fields.char(string="Question Title", size=256, required=True),
'description' : fields.text(string="Question Description", required=True),
'date_of_q_created': fields.function(_date_of_q_created, string='Maximum Allowed'),
'category_question': fields.many2one('openacademy.categ', 'Question Category',readonly="True"),
}
def _date_of_q_created(self):
#DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
#date_time_question = datetime.datetime.strptime(datetime.datetime.now(), DATETIME_FORMAT)
date_time_question="2014-02-04 5:50:50"
return date_time_question
错误是:
File "/opt/openerp/my_modules/forum_nyros/course.py", line 9, in Course
'date_of_q_created': fields.function(_date_of_q_created, string='Maximum Allowed'),
NameError: name '_date_of_q_created' is not defined
如何摆脱这个错误?
答案 0 :(得分:3)
python遵循从上到下的调用。将您的方法粘贴到_columns字典的顶部,像这样
def _date_of_q_created(self, cr, uid, ids, name, args, context=None):
#DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
#date_time_question = datetime.datetime.strptime(datetime.datetime.now(), DATETIME_FORMAT)
date_time_question="2014-02-04 5:50:50"
return date_time_question
_columns = {
'name' : fields.char(string="Question Title", size=256, required=True),
'description' : fields.text(string="Question Description", required=True),
'date_of_q_created': fields.function(_date_of_q_created, string='Maximum Allowed'),
'category_question': fields.many2one('openacademy.categ', 'Question Category',readonly="True"),
}
你错过了参数。