콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
12445 화면

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


아바타
취소
관련 게시물 답글 화면 활동
2
2월 23
2739
0
4월 20
3944
3
6월 17
14389
0
3월 15
4033
1
5월 25
2427