Or maybe more versatile would be a context manager that accepts a database 
router. Something like the following?

with database_router(my_router):
   …



On Tuesday, April 28, 2015 at 3:26:48 PM UTC-4, Peter Coles wrote:
>
> When using multiple databases, I would love for a simple way to declare 
> which database should be used during execution of django ORM calls. Perhaps 
> this could even use a context manager and look something like this:
>
> # declare that all calls within this context should default to using 
> 'readonly' db instead of 'default'
> with database('readonly'):
>     things = models.MyThing.objects.all()
>
>
>     # inside this function call the 'readonly' db would be used too 
> (unless overridden by `.using(...)`)
>     more_things = some_lib.some_function(things)
>
> In my app I have a write database and a read-only replica. The read-only 
> replica might have a delay, so I don’t want to use it in normal live 
> requests, but I would like certain dashboards to use it. For this reason I 
> assume that the database router 
> <https://docs.djangoproject.com/en/1.8/topics/db/multi-db/#using-routers> 
> approach doesn't properly apply?
>
> Does something like this exist? If not, any thoughts on if it might be 
> useful and where I might consider poking around in the ORM?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/05bf8620-35be-49cf-b10c-6bb00d0923ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to