#python #xml #pdf #download #odoo-12
#python #xml #PDF #Скачать #odoo-12
Вопрос:
Я хочу отобразить вложение на странице на моем веб-сайте, я создаю поле 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_usamp;amp;field=f.attachementamp;amp;filename_field=f.attachement_filenameamp;amp;id={{ f.id }}">Download2</a></td>
</tr>
</t>
</p>
</div>
</div>
</template>
по-прежнему он ничего не отображает для прикрепления
я хочу что-то вроде изображения
Ответ №1:
я нахожу решение своей проблемы для загрузки вложения на веб-сайте, которое я добавляю в свой контроллер 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>
я нахожу этот модуль
ссылка