Wouldn't a database router like this sort of do the thing for now...

==settings.py==
DATABASE_ROUTERS = ['dbrouter.AppRouter',]
==dbrouter.py==
APPS_WITH_DB=('my_app_with_same_name_as_db',
    )

class AppRouter(object):
    """A router to control all database operations on models in
    that belongs to a app in APPS_WITH_DB"""

    def db_for_read(self, model, **hints):
        if model._meta.app_label in APPS_WITH_DB:
            return model._meta.app_label
        return None

    def db_for_write(self, model, **hints):
        if model._meta.app_label in APPS_WITH_DB:
            return model._meta.app_label
        return None

    def allow_relation(self, obj1, obj2, **hints):
        if (obj1._meta.app_label in APPS_WITH_DB) or
(obj2._meta.app_label in APPS_WITH_DB):
            return True
        return None

    def allow_syncdb(self, db, model):
        "Make sure the app only appears on the db where it belongs"
        #print "db=%s, app=%s, model=%s" % (db, model._meta.app_label,
model)
        if db in APPS_WITH_DB:
            return db == model._meta.app_label
        elif model._meta.app_label in APPS_WITH_DB:
            return False
        return None



On Jan 19, 4:35 pm, Russell Keith-Magee <freakboy3...@gmail.com>
wrote:
> On Tue, Jan 19, 2010 at 12:20 AM, Tobias McNulty <tob...@caktusgroup.com> 
> wrote:
>
> > On Mon, Jan 18, 2010 at 11:04 AM, Bill Hubauer <bhuba...@gmail.com> wrote:
>
> >> One of the use cases that may be common for multiple database support is
> >> being able to combine multiple Django applications that require different
> >> databases into a single site.   This is exactly what I need to do for one
> >> project.   This can be done with the new multiple database support, but it
> >> feels heavy handed to me to require the "integrator" go through all of the
> >>applicationcode and insert "using" specifiers.   I also get nervous to
> >> about missing some places where it would be required.
>
> >> I've reviewed the code related to the selection of the default database
> >> and think that it wouldn't be too hard to make it possible to doapplication
> >> specific defaults to database settings.   It would mostly be refactoring 
> >> the
> >> django.db.DEFAULT_DB_ALIAS constant into a function, and then deciding the
> >> best way to allow the user to specify a default databaseperapplicationin
> >> the settings file.
>
> >> Has there been any consideration or discussion of this type of
> >> functionality?
>
> > There has been.  See:
>
> >http://groups.google.com/group/django-developers/browse_thread/thread...
>
> > If I recall correctly, the resolution was basically "not in this phase,"
> > i.e., this is something to be worked out in a future release of Django.
>
> You recall correctly :-)
>
> The goal for 1.2 is to get enough of the plumbing in place so that
> enthused individuals can use multi-db if they need to. The clean
> public API that addresses will be added (hopefully) in 1.3, using the
> experiences and guidance gathered from early adopters of the raw API.
>
> Yours,
> Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to