Again I was caught, in my slow progress with PyQt. Now I am with another example of connection with bbdd. The example is simple a QDialog, in which I have a button and pressing it inserts a record in a bodd Mongodb. The program I have divided into the main and another which has the method of the bbdd. I do not finish to catch the matter of importing the classes from another file
main.py
from PyQt5.QtWidgets import QDialog, QMessageBox
from PyQt5 import uic
#si el archivo bbdd es en el mismo directorio que main
import bbdd
#si el archivo bbdd esta en una carpeta hija llamada bbdd dentro
from bbdd import bbdd
class ventana(QDialog):
def __init__(self):
QDialog.__init__(self)
uic.loadUi('ui.ui')
self.boton.clicked.connect(self.Accion)
def Accion(self):
¿¿¿¿¿¿¿¿¿?????????
bbdd.py
from pymongo import MongoClient
class bbdd():
def ficha(self):
self.serverdb = self.MongoClient('10.10.10.10', 27017)
self.db = self.serverdb.ERP
self.coleccion = self.db.Tabla
self.coleccion.insert({'_id':22,'Nombre':'pepe', 'años':20})
self.serverdb.close()
Where I put:
¿¿¿¿¿¿¿¿¿?????????
I put:
self.serverdb = MongoClient('10.10.10.10', 27017)
self.bd = self.serverdb.ERP
self.coleccion = self.bd.Fichas
self.coleccion.insert({'_id': 22, 'Nombre': 'pepe', 'años': 20})
self.serverdb.close()
It works perfectly. The question of putting the bbdd method, apart is because I have thought of the program to create other methods that will connect to different bbdd and collections (tables). Why have I chosen Mongodb? For doing something different.
You can explain to me how I have to import it.