Skip to Content
Menu
This question has been flagged
2 Replies
4753 Views

I have to develop a module that is called news feed for posting new news feed to a website but when I am doing this I can not retrieve images from the database to view on the website. I have to get Title and Content but the image is not yet. 

anyone can help me how to fix

below is sample code that I use to retrieve title as well as content 


<table> 
<tbody>
<t t-foreach = "posted" t-as = "news_feed" >
<td> <b> <t t-esc = "news_feed.news_feed_title" /> <br/> </b> <t t-esc = "news_feed.news_feed_content" /> <br/> </td> </t> </tbody>










</table> 

Avatar
Discard
Author Best Answer

Dear Ivan Thanks for your prompted action but to be clear with the Issue let me share u code snippet for the controller as well as template 

with Kind Regards

templete >>>

<template id = "posted_news_feed" name = "News Feed" >
<t t-call = "website.layout" >
<div class = "container" >
<table>
<tbody>
<t t-foreach = "posted" t -as = "news_feed" >
<td>
<t t-if = "o.name" t-set = "web.news.content"
t-value = "o.get_cover_image (o.name)" /> <img
t-if = "web.news.content"
t-att-src = "image_data_uri (web.news.content)"
style = "max-height: 45px;" alt = "Cover Image" /> <b> <t t-esc = "news_feed.news_feed_title" /> <br/> </b> <t t-esc = "news_feed.news_feed_content" /> <br/> < / td> </t> </tbody> </table> <









Controller file 

class GetNewsFeedContent (http.Controller): 

@ http.route ( '/ news' , website = True, type = "http" , auth = 'public' , csrf = False )
def news_posted ( self , ** kw ):
posted = request.env [ 'web.news.content' ] .sudo (). search ([])
# last_id = request.env ['web.news.content']. sudo (). search ([]) [- 1] .id
print ( "Saved news are ..." , request.render (
"news.posted_news_feed" , {
'posted' : posted
})
Avatar
Discard

Hi, what is the binary field name ? Is it on web.news.content model ?

Author

Hi,

it is on the ir_attachment table

Author

the field name is cover_image

The field name is cover_image in web.news.content ?

Can you try this

<img t-att-src="'/website/image/web.news.content/' + news_feed.id + '/cover_image'"/>

Best Answer

Hi,

There is a controller that allow users to fetch images from database to website:

http://yourdomain.com/website/image/your_model/record_id/field_name

For example:

http://yourdomain.com/website/image/product.product/1/image

Regards,
Ivan

Avatar
Discard