On Tue, Jun 15, 2010 at 7:12 PM, johan de taeye
<[email protected]> wrote:
> Hello,
>
> In my application a number of databases are configured with identical
> schemas.
> From a dropdown box on the screen, the user selects the database he/
> she wants to work with. The selected database is stored on the
> cookie.
> An object with the same primary key can be created in each schema by
> the user.
>
> The above means objects can't be routed to the correct database based
> on their primary key.
> Only by looking at the request I know what database is required.
>
> From the documentation (and after digging a bit in the code) I think
> the database router concept doesn't support this type of usage.
> Is this possible somehow?
> Is it feasible to pass the request as a hint to the router somehow?
You can't do this with a router; as you've noted, the router doesn't
have any information about the request in which it is being used.
However, you could do it by manually requesting your database
connection whenever you use the database. For example:
Author.objects.using('otherdb').filter(...)
will perform a query that is guaranteed to operate on the 'otherdb',
regardless of what the router says.
The parameter 'otherdb' is just a string, so it could be determined
using some logic based on the request. This will require that you pass
the database assignment information around your project -- but you
would have needed to do this anyway if you wanted to pass hints to the
router.
Yours,
Russ Magee %-)
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.