如何下载Odoo的Binary字段的文件内容
-
这个问题似乎很奇怪,当然是在对象表单视图的对应字段上点击那个下载按钮:

但是,比如我有一个需求,需要创建一个下载所有的对象的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>
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