Monday, January 30, 2012

Routing to database based on user

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPJxM4AAoJELi8GfiSMn9y1jQIAKu3zgO4wfcOIXKMCueEHYyQ
qqIU1RFQB00wV72nwo8EfMKBXisxSc7TAmUOpER77NBaDmaelnvKNPI3ADmenbhw
MzTrCl5bdZyMT6f3xenlN660thg/KlLD6sclJ42gHgKM1UMJxTRkyYf4mGFhw8N2
NGQmAzUNrlze2y3+WdIo/Y/h2MqI0cExNlX0pKHhgDGaRzMWgeRJ93POSRm/h1tp
LkduNGRXFhXYB9p6pAaXi/K7gYoBMwRwpq27awdK+kWElKr5NueNpmjnJtzpujOv
AJDVz2xFNAiR79pywWCPCtakqwQIji11ZS4ZDO34g1QP6TwOrEol4HFRogJelM4=
=u9se
-----END PGP SIGNATURE-----
Hey guys,

I'm writing a django project that will require me to route queries to
certain large databases based on who the logged in user is.

So all the tables for django.contrib.auth and session and stuff will be
in the 'central' database, as well as a table that maps users to which
database they need to use for the main app.

Can you help me come up with a way of routing database queries this way
using a Django database router?

At the start of the view could I take the logged in user from
request.user or wherever it is, and some how provide that variable to my
database router for the rest of the request?

All suggestions welcome.

Cheers!

Tom

No comments:

Post a Comment