Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
12776 Представления

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 Ответы Просмотры Активность
2
февр. 23
3092
0
апр. 20
4175
3
июн. 17
14764
0
мар. 15
4305
1
мая 25
2954