Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
12800 Tampilan

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  ?





Avatar
Buang
Jawaban Terbai

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


Avatar
Buang
Jawaban Terbai

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

Avatar
Buang
Penulis Jawaban Terbai

I solved

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


Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Feb 23
3105
0
Apr 20
4183
3
Jun 17
14777
0
Mar 15
4339
1
Mei 25
2987