On May 16, 12:18 am, charettes <
charett...@gmail.com> wrote:
> Using django-hosts I managed to put together a simple setup that maps
> subdomains to databases.
>
> First, I have a default database with a table mapping sudomains to database
> name and a middleware that tries to load the correct object based on the
> match provided by django-hosts.
>
> In my settings I have a *placeholder* database that gets replaced by the
> middleware if the subdomain is mapping to a database.
>
> Finally I have a database router that returns the *placeholder* db alias
> when models are subdomain specific.
>
> This setup is working pretty well so far.
How to implement "database per client" is a commonly asked questions
in django-users. So, if you have something to share I think there
would be interested users.
Note that what you have done above will work only in 1.4+. In 1.3 the
connections dictionary wasn't thread-local object, and thus you are
changing the placeholder database for all threads - not just the
currently running thread.
- Anssi