How can I call a custom Django manage.py command directly from code with specific database connection - django

i followed this solution to run customer django command programmatically , but it is limited for just one database connection.
I have django app configured with multiple database , is it possible to run custom django command using specific database connection?
exactly like when we use connections["DB_NAME_CONNECTION"].cursor() to execute an sql query
thanks a lot for your help!

One option is to create a new settings module (here's a guide) that contains your specific database connection configuration, and then use that settings module when using call_command():
management.call_command('mycommand', '--settings=mysite.settings.specificconnection')

Related

Implement LiteSync on Django

I've tried to write sync sqlite database between 2 different Server but same app and DB. But when i turn on litesync.io in console, it doesnt synchronize the Django project with Django project in another server. I know it's wrong because i must configure it first in django project, but i've tried to change NAME of DATABASES into URI and it not work. I've tried it in console to execute query, it works, but not in Django Project. So, how to implement litesync on Django project? How to save data into Sqlite DB by URI?

Connect to databases dynamically in Django

I'm new to Django.
My project database architecture is like
Having 'Auth_DB' contains all the users login details.
Once user logged in, then in need to fetch the details from the other DB. Here i have databases for each user individually, like:
user_0001
user_0002
user_0003
user_0004
user_0005
Can any one please help how can i achieve this.
Thanks in Advance.
Followed Django multiple and dynamic databases
In summary, this is the process:
Add the new database to settings (at runtime)
Create a file to store these settings for reloading when the server is restarted (at runtime)
Run a script which loads the saved settings files (whenever the server is restarted)

How to use a mysql table of a particular django app in another django app if the is same?

I am trying my hand at Python. I have a created a simple app with MySQL as a back end and I want to use the application's table in another app.
Both of the applications are for the same project. Please help
Make sure all your app in registered in settings.py.Then import the model to other by appname.models.Modelname.
Execute Query:
ModelName.objects.all()

How to make django do user independent or session independent tasks?

I am working on a project which periodically downloads stock details as a json file from a web server and save locally for user requestes .Since it is not appropriate to download the same for each user request i need help in doing that
I know how to do it using cron but i prefer it in django itself ..
Write a django command using while True loop and thread.sleep(intervaltime) function.
And after starting django server, run this python manage.py commandname

Problem getting CouchDB running w. Django

I'm having trouble getting my Django project to work with a CouchDB database.
I'm running Python 2.6.6, Django 1.3, and Lion on a Mac
I've got Django, CouchDB, and CouchDBKit installed. I can import all of them from the python interpreter without a problem. If I go to my CouchDB database URL, I can see the db.
The problem is, when I try to go to my django project URL, I get the following error:
You haven't set the database ENGINE setting yet.
I have the following lines in my settings.py file:
COUCHDB_DATABASES = (
('my_project.my_db', 'http://127.0.0.1:5984/my_db'),
)
The only possible solution I've found so far, is to set a throwaway database in the normal database engine settings. But, this just throws another error, because Django starts looking for database tables in the throw away DB.
Edit with new info:
I'm accessing my DB via an SSH tunnel
I'm able to create and access a CouchDB from the python interpeter.
I've run a test from the python interpreter, to access the app DB (again, via the tunnel), and the returned data accurately.
It's just when I try to access the actual site from a browser URL, I get the engine not defined error.
Django seems to be trying to use a normal DB (which isn't setup), instead of the CouchDB.
Any ideas?