Is it OK to set the database name setting depending on subdomain for each request?
Something like this in a middleware:
from django.db import connection
company_name = ... # read the subdomain
connection.settings_dict['NAME'] = 'db_' + company_name
Is it OK to set the database name setting depending on subdomain for each request?
Something like this in a middleware:
from django.db import connection
company_name = ... # read the subdomain
connection.settings_dict['NAME'] = 'db_' + company_name
I think it is not OK.
Are you trying to make a multi-tenant application? Look at this question:
See also the sites framework and multiple databases (specially routers, "Manually selecting a database" and "Exposing multiple databases in Django's admin interface".