Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
12818 มุมมอง

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
3116
0
เม.ย. 20
4193
3
มิ.ย. 17
14789
0
มี.ค. 15
4386
1
พ.ค. 25
3014