Home > Net >  In django, can the .using('db') keyword take a variable?
In django, can the .using('db') keyword take a variable?

Time:07-02

Example.objects.using('db').raw()

Instead of db could we have a variable that would correspond to the appropriate database?

CodePudding user response:

Yes, you can.

my_db = "default"

Example.objects.using(my_db).get(pk=1)

my_db = "other_db_key_from_DATABASES"

Example.objects.using(my_db).get(pk=1)
  • Related