gpt4 book ai didi

python - OpenERP 名称错误 : name '_date_of_q_created' is not defined

转载 作者:太空宇宙 更新时间:2023-11-04 01:20:33 24 4
gpt4 key购买 nike

我正在创建 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

如何摆脱这个错误?

最佳答案

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"),
}

你错过了参数。

关于python - OpenERP 名称错误 : name '_date_of_q_created' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com