Reputation: 861
Odoo ORM has Binary type field which can hold images. The problem with these images is that they are delivered with HTML as base64 encoded. These add up to the HTML size and can't be cached or delivered via CDN.
I need to add images uploading to a module. These images will then be displayed on the website. Is there an alternative approach to this? Model code below:
class BannerImage(models.Model):
_name = 'banner.image'
_description = 'Banner Image'
image_desktop = fields.Binary('Desktop Image', attachment=True)
image_mobile = fields.Binary('Mobile Image', attachment=True)
start_date = fields.Date("Start Date")
end_date = fields.Date("End Date")
action = fields.Char("URL")
desc = fields.Text("Additional Description")
banner = fields.Many2one('banner.banner', "Banner")
View for backend declared as below:
<record id="action_view_banner_images" model="ir.actions.act_window">
<field name="name">Banner Images</field>
<field name="res_model">banner.image</field>
<field name="view_mode">tree,form</field>
</record>
These are used in HTML template as below:
<div class="banners">
<t t-foreach="banners.images" t-as="banner_image">
<img class="media-object img-responsive" t-attf-src="data:image/*; base64,{{banner_image.image_desktop}}" />
</t>
</div>
Is there another way to call these images, probably using URLs?
Upvotes: 0
Views: 2024
Reputation: 66
you can use image "t-attf-src=/web/binary/image?model=ir.attachment&field=datas&id=(your img ID)" instead of "t-attf-src="data:image/*;.... "
Upvotes: 1