Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
12774 Переглядів

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  ?





Аватар
Відмінити
Найкраща відповідь

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))


Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Автор Найкраща відповідь

I solved

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


Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
Controller not working Вирішено
2
лют. 23
3091
0
квіт. 20
4175
3
черв. 17
14764
0
бер. 15
4305
1
трав. 25
2953