Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
5658 Представления

I want to use sql queries in CustomerPortal class controllers. I wrote following code:

request.cr.execute("""my query""")
result = request.cr.fetchall()
but I get the following error:
AttributeError: 'CustomerPortal (extended by PortalAccount, Custome' object has no attribute 'cr'a
what should I do?
Аватар
Отменить
Лучший ответ

Hello Arian, try to use 'request.session.cr' instead of 'request.cr'.


Аватар
Отменить
Автор

thanks! request.env.cr worked for me aswell.

Лучший ответ

https://github.com/odoo/odoo/blob/13.0/addons/web/controllers/main.py#L1551

## inside try

registry = odoo.modules.registry.Registry(dbname)
with registry.cursor() as cr:
cr.execute(""" query """)
row = cr.fetchone()
Аватар
Отменить
Related Posts Ответы Просмотры Активность
3
мая 20
13068
3
окт. 15
6856
2
июл. 25
1852
1
мая 24
3199
2
февр. 24
2537