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

I want to access database in my below method in openerp 7:

    @openerpweb.httprequest

def index(self, req, data, token):

data = json.loads(data)

model = data.get('model', [])

columns_headers = data.get('headers', [])

rows = data.get('rows', [])

return req.make_response(

self.from_data(columns_headers, rows),

headers=[

('Content-Disposition', 'attachment; filename="%s"'

% self.filename(model)),

('Content-Type', self.content_type)

],

cookies={'fileToken': token}

)

I accessed database in odoo 8 using request.cr in same method.

but here when I tried req.cr and used it too access method, it throws error

cr is not attribute of request.

So tell me a way to access either cr or database somehow.

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

You could do it like:

registry = openerp.modules.registry.Registry(dbname)
with registry.cursor() as cr:
    cr.execute("""SELECT * from res_users""")
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 24
11298
2
thg 8 21
13524
5
thg 8 20
7476
1
thg 12 19
5375
0
thg 9 17
3516