首页 > 解决方案 > 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 的链接。

标签: pythonxmlodoo

解决方案


推荐阅读