Loading from multiple databases in Django custom command -
Loading from multiple databases in Django custom command -
if creating django custom command, can info more 1 database? in c:/project/myproject/settings.py, have:
databases = { 'default': { 'engine': 'django.db.backends.sqlite3', 'name': os.path.join(base_dir, 'db.sqlite3'), } } then in c:/project/myproject/myapp/management/commands/mycommand.py, have:
users = user.objects.all() where user defined in c:/project/myapp/models.py.
but if have several databases, called db1.sqlite3, db2.sqlite3, db3.sqlite3 etc., , want load user objects these databases in custom command? possible?
from the documentation:
you can select database queryset @ point in queryset “chain.” phone call using() on queryset queryset uses specified database.
you define more databases in settings.py, give them names , pass name using('db_name').
django
Comments
Post a Comment