Hello,
I'm trying to connect to a mysql database within a self-written odoo app.
Here is my code:
from odoo import api, fields, models
import mysql.connector
MYSQL_USER = 'root'
MYSQL_PASSWORD = 'root'
MYSQL_HOST = 'localhost'
MYSQL_DATABASE = 'data'
class importlogic(models.Model):
_name = 'test.data'
_inherit = 'test.data'
cnx = None
def action_import_data(self):
self.process()
def process(self):
self.connect_mysql()
def connect_mysql(self):
self.cnx = mysql.connector.connect(user=MYSQL_USER,
password=MYSQL_PASSWORD,
host=MYSQL_HOST,
database=MYSQL_DATABASE)
And I receive the following error message:
AttributeError: 'test.data' object attribute 'cnx' is read-only
For the moment I have no idea why this appears, can someone help me?
Thank you.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
1
Trả lời
1810
Lượt xem
Okay, I found the problem
should be importlogic.cnx > the classname because it is the class attribute https://www.toptal.com/python/python-class-attributes-an-overly-thorough-guide
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng ký