Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
12795 Lượt xem

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  ?





Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I solved

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


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 23
3104
0
thg 4 20
4182
3
thg 6 17
14771
0
thg 3 15
4337
1
thg 5 25
2980