gpt4 book ai didi

report - 将变量 get_pdf() 保存到 fields.binary

转载 作者:行者123 更新时间:2023-12-01 15:30:44 24 4
gpt4 key购买 nike

我想通过 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 函数有什么问题吗?

最佳答案

使用encodestring()代替decodestring()

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)

关于report - 将变量 get_pdf() 保存到 fields.binary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45234207/

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