Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
12763 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Autor Nejlepší odpověď

I solved

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


Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
úno 23
3074
0
dub 20
4167
3
čvn 17
14756
0
bře 15
4291
1
kvě 25
2944