Skip to Content
Menú
This question has been flagged
3 Respostes
12379 Vistes

Hi

I can't get the model object from controller

class WebExtraControllers(http.Controller):

@http.route('/foo', type='http', auth="public", website=True)
def foo(self, **post):
        # ..........
obj = self.env['res.partner'].function()

But the result is 

AttributeError: 'WebExtraControllers' object has no attribute 'env'

What can I do  ?





Avatar
Descartar
Best Answer

Please try:

env from request, ie, request.env
eg:

prod_obj = request.env['product.product'].sudo().search([])

or

env = request.env(context=dict(request.env.context, show_address=True, no_tag_br=True))


Avatar
Descartar
Best Answer

I resolved this issue from looking at existing code and found this one helpful: request.session.model('res.users').browse(id)

Avatar
Descartar
Autor Best Answer

I solved

print http.request.env['res.partner'].function()


Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de febr. 23
2684
0
d’abr. 20
3894
3
de juny 17
14342
0
de març 15
3951
1
de maig 25
2318