Opened 9 years ago

Closed 9 years ago

#24815 closed New feature (invalid)

Custom settings for database alias

Reported by: Miguel Angel Velazco Owned by: nobody
Component: Uncategorized Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Miguel Angel Velazco)

It could be excelet to be able to set custom settings depending the database alias. An excelent example could be the management of the media files.

Maybe to do something like this:

settings.py

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

DATABASES = {
   'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'uno.sqlite3'),
    },
    'another': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'uno.sqlite3'),
        'ADDITIONAL_SETTINGS': {
            'MEDIA_ROOT': os.path.join(BASE_DIR, "custom_media"),
        }
    },
}

Is important to say that this custom settings should be applied when a database router switch databases.

Change History (2)

comment:1 by Miguel Angel Velazco, 9 years ago

Description: modified (diff)

comment:2 by Carl Meyer, 9 years ago

Resolution: invalid
Status: newclosed

Thanks for the suggestion. I don't believe this feature is possible, though, because settings are process-global, whereas you can easily have multiple threads of execution each talking to different databases at different times.

In general, changing the value of settings at runtime is not safe or supported.

Note: See TracTickets for help on using tickets.
Back to Top