Friday, September 2, 2011

Re: Multiple Database Routing Based on Site

The only solution I can directly think of, since the SITE_ID is in
settings.py would be to use some python logic to determine the
database for that site.

eg.
if SITE_ID == 1:
... Database settings for site 1 here ...

Use an if-then like this in your settings.py.

Now if what your going after is storing the SITE_ID in a user's
profile and using that for routing, this will be more complex, as you
will need to code a new databasebackend to perform the routing, and
perhaps some middleware and an authbackend.

Mind you, I haven't done much work on multiple databases, so these are
just ideas on how I think it might be done.

On Sep 1, 9:54 pm, Terribyte <mdra...@gmail.com> wrote:
> I had a kind of crazy idea and I wanted to bounce it off of some
> people with a lot more django experience than I.
>
> Here's my scenario...
>
> I would like 1 code base, this code base services potentially hundreds
> of businesses, each of which I want to have a copy of the same schema
> but with data only relevant to that business.
>
> Basically my idea is the following
> If the model is a Site object or User object, route to the default
> database, otherwise route reads and writes to a database name I'll set
> in the sites table.
>
> The trick is I need to set the SITE_ID for the current request, and
> I'm not sure exactly When that should happen (after login of course),
> or if this idea is even workable.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment