我想从get_pdf函数自动将变量保存到fields.binary(email_attachment_file)中。
我的代码如下:
class example_example(models.Model):
email_attachment_file = fields.Binary('Data (.txt,.pdf)')
email_filename = fields.Char('Filename')
def generate(self,etc..):
report_name = "report_name_template"
datas = {
'ids':[],
'model' : etc,
'form' : etc
'context': context
}
moddelReport = self.pool.get('report')
alpha = modelReport.get_pdf(cr, uid,[],report_name,None,datas,context=context)
#alpha = base64.decodestring(alpha)
#alpha = alpha.decode('unicode_escape').encode('utf-8')
# --------- how to save alpha variable into fields.binary
而且,modelReport.get_pdf函数有什么不对吗?
答案 0 :(得分:2)
使用编码字符串()代替解码字符串()。
report_obj = self.pool.get('report')
data = modelReport.get_pdf(cr, uid,[],report_name,None,datas,context=context)
self.email_attachment_file = base64.encodestring(data)