Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
3 Besvarelser
12796 Visninger

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
Kassér
Bedste svar

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
Kassér
Bedste svar

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

Avatar
Kassér
Forfatter Bedste svar

I solved

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


Avatar
Kassér
Related Posts Besvarelser Visninger Aktivitet
2
feb. 23
3104
0
apr. 20
4182
3
jun. 17
14771
0
mar. 15
4337
1
maj 25
2980