GlobalConfig editor
Use the optional Django-GC integration for typed settings that staff can inspect or edit while the application is running. Define keys and categories in Django settings and register Django-GC's own ModelAdmin.
Install and declare a setting
This recipe uses Django-GC 1.1.5 or later for its explicit initialization
command. Keep both apps before django.contrib.admin.
pip install 'django-chassis[global-config]==1.0.23' 'django-gc>=1.1.5,<2'
# settings.py
from django_gc import CategoryDefinition, SettingDefinition, SettingType
INSTALLED_APPS = [
'django_chassis',
'django_gc',
'django.contrib.admin',
# Keep the other installed apps.
]
GLOBAL_CONFIG_CATEGORIES = [
CategoryDefinition(id=1, code='catalog', name='Catalog')
]
GLOBAL_CONFIG_DEFINITIONS = [
SettingDefinition(
key='catalog.max_page_size',
description='Maximum page size in the public catalog',
default_value=50,
value_type=SettingType.INTEGER,
category_id=1
)
]
python manage.py migrate
python manage.py initialize_global_configs
Run initialization after adding or changing definitions. It synchronizes metadata and keeps existing live values. Use the initialization command after migrating the schema.
Register the editor
Add this to the module that constructs your Chassis AdminSite. It uses that site's existing URL mount and authentication.
from django_gc.admins import GlobalConfigAdmin
from django_gc.models import GlobalConfig
site.register(GlobalConfig, GlobalConfigAdmin)
Open the model from Django Admin or import SETTINGS_SIDEBAR_LINK from
django_chassis.sidebar and add it to the site's sidebar_items. With
AdminSite mounted at /admin/, the catalog appears at
/admin/django_gc/globalconfig/.
| Requirement | Effect |
|---|---|
django_gc.view_globalconfig | Open the catalog and see settings allowed for the operator. |
django_gc.change_globalconfig | Save editable settings allowed for the operator. |
is_read_only=True on a definition | Show the value in read-only mode even with change permission. |
SettingType.SECURE | Mask the current value. A user with change permission sees a blank password input. Configure Django-GC's encryption key when storing a secure setting. |
| Protected provider key (Django-GC 1.1.5+) | Exclude the key from the catalog. Its normal change URL uses the provider's own editor and permission checks. |
Use the category tabs, search or filters and open the row action. After a successful edit the catalog reopens with the original filters. If another operator has changed the setting since it was opened, the save is rejected and the catalog reports the conflict. Open the row again before retrying.
Project code reads the typed value through Django-GC.
from django_gc.services import GlobalConfigService
max_page_size = GlobalConfigService().get_value('catalog.max_page_size')
Chassis providers
Added in 1.0.23With Django-GC 1.1.5 or newer, add Chassis providers to the existing
GLOBAL_CONFIG_PROVIDERS list. For website impersonation, use the provider
below. Choose an unused numeric category ID for a new configuration.
from django_gc import ProviderDefinition
GLOBAL_CONFIG_PROVIDERS = [
ProviderDefinition(
provider='django_chassis.chassis_configuration_provider.ChassisConfigurationProvider',
category_ids={'project': 1}
)
]
The provider defines the nullable string chassis.impersonation_frontend_url.
Repeat initialize_global_configs after registration and set the full website
entry URL in the catalog. If the project already defines the key, remove its
old setting definition and pass its existing category ID to the provider.
Remove any duplicate category declaration for that ID from
GLOBAL_CONFIG_CATEGORIES, since the provider declares it. Other settings
can keep referring to that ID. Initialization preserves the live value. See Users and access
for website integration.
Use django_chassis.enums.ChassisConfigurationKey.IMPERSONATION_FRONTEND_URL
to reference the key in Python. Projects with a shared key class can inherit
django_chassis.global_config_keys.ChassisGlobalConfigKeys and add their own keys.
It also exposes LOGGING_SENSITIVE_KEYS and the RISK enumeration.
See logging settings and risk observation for their optional providers. Django-GC definitions covers supported types, cache configuration and provider-owned keys.