python - Odoo 12. 如何从二进制字段中获取链接
问题描述
如何获取文件名的链接?我得到了文字:(
class UploadFile(models.TransientModel):
_name = 'upload.file'
product_attribute_value_id = fields.Many2one('product.at[![enter image description here][1]][1]tribute.value', string='Attribute Value',
required=True, ondelete='cascade', index=True)
product_id = fields.Many2one('product.template', string='Product', required=True)
file = fields.Binary(string="Upload file")
file_name = fields.Char("File Name")
@api.multi
@api.onchange('product_attribute_value_id', 'product_id')
def onchange_data_product(self):
if not self.product_attribute_value_id or not self.product_id:
return
r = open('D:\picture\pdff.pdf', "rb").read()
# base64.b64encode(r).decode('utf-8')
self.file = base64.b64encode(r)
<record id="upload_file_form" model="ir.ui.view">
<field name="name">upload.file.wizard</field>
<field name="model">upload.file</field>
<field name="arch" type="xml">
<form string="Upload attributes file">
<group>
<field name="product_id" string="Product"/>
<field name="product_attribute_value_id"/>
<field name="file" widget="binary" filename="file_name" string="Binary"/>
<field name="file_name" invisible="1"/>
</group>
<footer>
<button name="save_file" string="Save" type="object" class="btn-primary"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
它是向导形式。当用户更改两个字段 product_attribute_value_id 和 product_id 时,我想查看指向 pdf 的链接。
解决方案
推荐阅读
- node.js - 节点js中的可交换rsa
- python - 有没有办法在 OWA 找到含硒的物品?
- javascript - 我在理解 $("button").click() 和 $("button")[0].click() 的不同行为时遇到问题
- jmeter - HTTP 请求中文件协议的使用
- npm - npm - 修复 package-lock.json 中易受攻击的依赖项
- java - Cloud SQL 和 App Engine 之间的连接超时
- reactjs - Formik 重置错误
- python - 如何重塑文本数据以适合 keras 中的 LSTM 模型
- php - Laravel 5.8 公用文件夹重定向到“/索引”页面
- sorting - 如何根据谷歌应用脚本中的电子表格日期发送电子邮件?