Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 培训
  4. 如何下载Odoo的Binary字段的文件内容

如何下载Odoo的Binary字段的文件内容

Scheduled Pinned Locked Moved Odoo 培训
binary fieldodoo技术
1 Posts 1 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    digitalsatori
    管理员
    wrote on last edited by
    #1

    这个问题似乎很奇怪,当然是在对象表单视图的对应字段上点击那个下载按钮:
    image_btn.png

    但是,比如我有一个需求,需要创建一个下载所有的对象的Binary字段中的文件的页面,该如何做呢?

    实际上对象上的Binary对象的链接是下面这样的:

    http://127.0.0.1:8069/web/content?model=<module_name>&field<field_name>&filename_field=<field_filename>&id=<object_id>

    其中:
    module_name - Binary字段对应的模型名称
    field_name - Binary字段的名称
    object_id - 对应的记录id.
    field_filename - Binary字段对应的文件名称的字段(非必选项)

    所以我们要创建一个按钮,点击下载文件的代码如下:

    file_url = "http://127.0.0.1:8069/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>"
    return {
        'type': 'ir.actions.act_url',
        'url': file_url,
        'target': 'new'
    }
    

    而在Qweb报表或web页面中,我们可以这样处理:

    <t t-foreach="files" t-as="f">
        <tr>
            <td><t t-esc="f.name"/></td>
            <td><a t-attf-href="/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>">Download</a></td>
        </tr>
    </t>
    

    【上海先安科技】(tony AT openerp.cn)

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Tags
    • Popular
    • Users
    • Groups