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
- Akuntansi
- Inventaris
- PoS
- Project
- MRP
Pertanyaan ini telah diberikan tanda
1
Balas
1768
Tampilan
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
Menikmati diskusi? Jangan hanya membaca, ikuti!
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
Daftar