jlaine/qdjango

Bind Database Connection to certain classes

Opened this issue · 2 comments

Hello Jeremy,
we are using QDjango in our project for some time now and it worked well.
But now we added another database which stores a different type of data.
The problem now is that, as far as I can see, there is only a globally registered database connection.
We now have to change this connection in each method that does something with the database.
Is there a possibility to bind a connection to certain classes?
For example registering a property for the connection in the class that inherits the QDjangoModel class.

Best Regards,
Daniel

Currently, no unfortunately there are no provisions for multi-db.

I'd be willing to review a DB routing proposal if it lines up with django's philosophy:

https://docs.djangoproject.com/en/1.10/topics/db/multi-db/

I added code to QDjango for testing that enables connecting a QDatabase object with a certain QDjangoModel when calling QDjango::registerModel(QDatabase)
When looking at the way Django does it, it seems a Router object would be registered with the model instead of directly giving the database.
Then QDjango could keep a map that keeps the Model->Router connection.