Skip to Content
Menu
This question has been flagged
3 Replies
11250 Views

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
Discard
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
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

I solved

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


Avatar
Discard
Related Posts Replies Views Activity
2
Feb 23
1697
0
Apr 20
3231
3
Jun 17
13361
0
Mar 15
3359
1
Oct 24
824