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
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
1
Beantwoorden
1809
Weergaven
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
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden