Hello,

I have a "dbname" field in my user Profile... and I have one database to 
store all default django data, like users, sessions etc.. when I try to get 
some ovject in a view, I will get to other database setted in "dbname" 
profile... I make this code:

from django.contrib.auth.models import User
from models import UserProfile

import threading

# Object to hold request data
request_cfg = threading.local()

class RouterMiddleware(object):
    """
    Set a flag if we are accessing Django admin to
    prevent database rerouting for the auth model.
    Remove the flag once the request has been processed.

    """

    def process_view(self, request, view_func, args, kwargs):
        if request.path.startswith('/admin'):
            request_cfg.admin = True

    def process_response(self, request, response):
        if hasattr(request_cfg, 'admin'):
            del(request_cfg.admin)
        return response

class UserSessionRouter(object):
    """
    Redirect database IO for the auth and sessions
    models to OldWebsite.com.

    """

    def db_for_read(self, model, **hints):
        if not hasattr(request_cfg, 'admin'):
            if model._meta.app_label == 'auth':
                return 'default'
            elif model._meta.app_label == 'accounts':
                return 'default'
            elif model._meta.app_label == 'sessions':
                return 'default'
            else:
                return UserProfile.dbname
        return None

    def db_for_write(self, model, **hints):
        if not hasattr(request_cfg, 'admin'):
            if model._meta.app_label == 'auth':
                return 'default'
            elif model._meta.app_label == 'accounts':
                return 'default'
            elif model._meta.app_label == 'sessions':
                return 'default'
            else:
                return UserProfile.dbname
        return None

But when I try to execute, show me these error: 

ImproperlyConfigured at /
settings.DATABASES is improperly configured. Please supply the ENGINE 
value. Check settings documentation for more details.

I think the django doesn`t get the correct database to use... and I have 
set all database in DATABASE in settings.py

In other words... all django default data use a "default" database, for all 
other data using a database setted in "dbname" in UserProfile.

How can I use this?

Best Regards,
F.H.

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

Reply via email to