我想在我网站的页面中显示附件,我在后端创建一个Many2many('ir.attachment')字段,我想显示一个按钮来下载或显示
这是我的代码字段
class Contact_us(models.Model):
_name = "contact.contact_us"
_description = "contact_us Pages"
name = fields.Char(string='Name')
description = fields.Html(string='Content')
attachement = fields.Binary('attachement')
attachment_ids = fields.Many2many('ir.attachment', 'car_rent_checklist_ir_attachments_rel',
'rental_id', 'attachment_id', string="attachement ids")
另一方面是我网站上显示的XML代码
<template id="about_us" name="about_us">
<t t-call="website.layout">
<t t-set="additional_title" t-value="about_us.name" />
<div id="main-page">
<div class="container">
<p class="text-right">
<h2 style="text-align: center;"><span style="font-size:16px;"><img t-attf-src="/website/image/maarefa.about_us/#{about_us.id}/imagePage/" style="" /></span></h2>
<h2 style="text-align: center;"><span style="font-size:18px;"><span style="color:#82661f;"><strong><t t-esc="about_us.name"/></strong></span></span></h2>
<div style="text-align: justify;font-size:16px;">
<t t-raw="about_us.description" />
</div>
</p>
</div>
</div>
</t>
<div id="main-page">
<div class="container">
<p>
<t t-if="about_us.attachment_ids">
<input t-att-value="about_us.attachment_ids" autocomplete="false" name="attachment_ids" t-att-id="'attachment_ids'+str(about_us.id)" class="youtube_link"
readonly="readonly" type="hidden"/>
<span class="embed-responsive embed-responsive-16by9" t-att-id="'iframe'+str(about_us.id)"></span>
</t>
<t t-foreach="about_us" t-as="f">
<tr>
<td><t t-esc="f.attachment_ids"/></td>
<td><a t-attf-href="/web/binary/saveas?model=maarefa.about_us&field=f.attachement&filename_field=f.attachement_filename&id={{ f.id }}">Download2</a></td>
</tr>
</t>
</p>
</div>
</div>
</template>
他仍然不展示任何东西作为附件 我想要类似图片的东西
答案 0 :(得分:0)
我为在网站上下载附件的问题找到了解决方案 我添加我的控制器py:
@http.route(['/page/my_page/<model("my.model"):file>'], type='http', auth="public", website=True)
def my_controller(self, about, **kwargs):
file = http.request.env['ir.attachment'].sudo().search([('res_model','=','my.model'),('res_id','=',file.id)])
print('file:--------------------->>>>>>>>>>',file)
values = {
'files': file,
}
return request.render("my_module.id_template", values)
和我在xml中的视图
<t t-foreach="files" t-as="f">
<div class="col-sm-4">
<a t-att-href="'/web/content/%i?download=true' % f.id">
<img src="/my_module/static/images/icons/backattach.png" style="width:82px; height:86px" />
<span t-esc="f.name" />
</a>
</div>
</t>
我找到了这个模块 link