Thursday, May 13, 2010

Multiple Database Simple Example

Hello,

I am using Django 1.2 RC 1 and have setup multiple databases. I have
everything working if I manually specify .using, for example:

SomeObjects = ModelInDefaultDatabase.objects.all() #This Works

SomeObjects = ModelInDatabase2Name.objects.using('Database2').all()
#This also Works


How can I make it so my models that are in Database 2 automatically
default to that database, so I do not have to use "using" on every
query? I tried adding "using" to the model and to Meta but that did
not work, so I assume I have to setup a database router, but I do not
understand how to apply the documentation example to what I assume is
this simple use case for multiple databases [all models should read/
write to the default database except for the models that ones are
defined to exist in other databases].

Anyone have a simple example of how to do this (or a link to one)?

Thanks for any advice.

Gregory Roby

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate