Please see the attached patch for using in models's Meta option, I also like this option.
This patch export some helper function from django.db, get_connection(name) get database connection by name get_current_connection() get current connection you can use follow function to ensure use special db connection: enter_connection_management(connection) leave_connection_management() Wei guangjing ----- Original Message ----- From: "mtrier" <[email protected]> To: "Django developers" <[email protected]> Sent: Sunday, December 28, 2008 10:37 AM Subject: Re: Multi Database use with statement Hi Wei, On Dec 27, 6:23 am, "wei guangjing" <[email protected]> wrote: > Hi, > > I write a patch for using with statement in python 2.5 and up for multi > database access, example code like this: > > # test.py > from __future__ import with_statement > from django.contrib.auth.models import User > from django.db import using > > with using('db1'): > print User.objects.count() # db1 user count > with using('db2'): > print User.objects.count() # db2 user count > print User.objects.count() # default db user count > A couple of ideas to throw in the mix. I'd like to see a Meta option. Like: Meta: using = 'db2' So you have a default for your model. Additionally what about just using the generative syntax for the using. It doesn't seem that a lot is to be gained by using the context manager. For instance: User.objects.using('db2').all() Also when thinking about third-party plugable applications you have to consider how you're going to handle that. If you have a third party app and you want it to all be directed to a particular database, how does that get handled in your scenario above? Just a couple of things to consider. Michael Trier --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" 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-developers?hl=en -~----------~----~----~----~------~----~------~--~---
using.diff
Description: Binary data
