تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
12726 أدوات العرض

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
فبراير 23
3021
0
أبريل 20
4161
3
يونيو 17
14714
0
مارس 15
4263
1
مايو 25
2904