How to render data from the external model in divs of a view?

255 Views Asked by At

I need your help, I have some divs in a view in odoo 13, I need to bring the data from an external model "maintenance.stage" render them in those divs, can someone give me an example of how to do it with a controller to bring those logs and be able to display them in those divs? every time i add a new record it should render in those divs.

enter image description here

enter image description here

1

There are 1 best solutions below

0
Alexis Yovanofski On

I hope this helps, This is a controller exemple:

class ControllerExemple(http.Controller):
    @http.route('/path/', auth='public', type='http', 
            methods=["GET","POST"], website=True)
    def function_exemple(self):
        obj = request.env['maintenance.stage'].browse(<id>)
        return request.render("module.your_view_id", {'object': obj})

There is a exemple view :

    <template id="your_view_id" name="Something">
        <t t-call="website.layout">
            <div class="container">
                <div><span t-out="object.the_field_you_need"/></div>
            </div>
        </t>
    </template>

It seems that you have several values to display, so use the foreach in your template :

    <template id="your_view_id" name="Something">
        <t t-call="website.layout">
            <t t-foreach="object.the_field_you_need" t-as="value">
                <div class="container">
                    <div><span t-out="value"/></div>
                </div>
            </t>
        </t>
    </template>

https://odoo-master.readthedocs.io/en/master/reference/qweb.html