A Django app that manages configurations per-site on a multi-site setup. These configs can be made avaialble to users of different sites or administerd via the Django admin.
Project description
Django Site Configs
Django Site Configs stores small, structured configuration objects per Django
site. It uses django.contrib.sites to choose the active site and stores all
config objects for that site in one SiteConfigModel.value JSON field.
The package is intended for project or app settings that should live in the
database instead of in settings.py, while still being represented in Python as
simple classes with defaults and optional form classes.
Requirements
- Python 3.10+
- Django 5.2 or Django 6.0
django.contrib.sites
The package dependency range is currently:
django>=5.2,<6.1
Installation
Install the package, then add the sites framework and siteconfigs to
INSTALLED_APPS.
INSTALLED_APPS = [
"django.contrib.sites",
"siteconfigs",
]
SITE_ID = 1
Run migrations:
python manage.py migrate
The model is registered with the Django admin as Site Setting.
Defining A Config
Create a class that subclasses SiteConfigBaseClass. Public class attributes
become default config values.
from django import forms
from django.utils.translation import gettext_lazy as _
from siteconfigs.config import SiteConfigBaseClass
class FeatureFlagsForm(forms.Form):
show_banner = forms.BooleanField(required=False)
class FeatureFlags(SiteConfigBaseClass):
_label = _("Feature flags")
_form_class = FeatureFlagsForm
show_banner = False
Instantiate the class to load values for the current site:
flags = FeatureFlags()
if flags.show_banner:
...
Pass a Site instance to load or save config for a specific site:
from django.contrib.sites.models import Site
site = Site.objects.get(domain="example.com")
flags = FeatureFlags(site=site)
Saving Values
Set attributes on the config object and call save().
flags = FeatureFlags()
flags.show_banner = True
flags.save()
Calling delete() removes only that config class's data from the site's JSON
record. It does not delete the SiteConfigModel row.
FeatureFlags().delete()
Optional Forms
If a config class sets _form_class, get_form() returns that form class.
This is useful when building custom admin or project views around a config.
config = FeatureFlags()
form_class = config.get_form()
form = form_class(initial={"show_banner": config.show_banner})
Storage Format
For each site, the package creates or updates one SiteConfigModel row with:
site: the DjangoSitekey: the config namespace, defaulting to"default"value: a JSON object keyed by each config class's full import path
Example value:
{
"myapp.config.FeatureFlags": {
"data": {
"show_banner": true
}
}
}
The namespace stored in SiteConfigModel.key can be changed with:
DJANGO_SITE_CONFIGS_SITE_CONFIG_NAME = "staging"
This lets one site have multiple named config records, such as default and
staging.
Current Behavior And Limits
- The current site is resolved with
Site.objects.get_current()when no site is passed to the config class. - Config values are plain JSON-serializable public attributes.
- Saving includes all non-callable public attributes on the config instance.
- The package provides the storage model and base class, but not a generic UI for editing every config class.
- The
deletedfield onSiteConfigModelis available for project-level soft delete workflows, butSiteConfigBaseClass.delete()removes the config data from the JSON value directly.
Development
Install test dependencies and run the test suite:
python -m pip install -e ".[test]"
python -m pytest src/siteconfigs develop
Check for missing migrations:
python develop/manage.py makemigrations --check --dry-run
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_site_configs-0.5.0.tar.gz.
File metadata
- Download URL: django_site_configs-0.5.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2a9cf5efa1b3e72080d6c4730ee96262068b5db03c72797c9c0a4f87db1d000
|
|
| MD5 |
5402eca319e7e7a00660031b2cc9ff4d
|
|
| BLAKE2b-256 |
69c5b83b3ad23546a318e7e6767b341bf51b33ce886c186d79f3c8510fe84295
|
Provenance
The following attestation bundles were made for django_site_configs-0.5.0.tar.gz:
Publisher:
python-publish.yml on renderbox/django-site-configs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_site_configs-0.5.0.tar.gz -
Subject digest:
d2a9cf5efa1b3e72080d6c4730ee96262068b5db03c72797c9c0a4f87db1d000 - Sigstore transparency entry: 1397485102
- Sigstore integration time:
-
Permalink:
renderbox/django-site-configs@9e281904c0a8538cd9ce9f4e5fe03f943fd42581 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/renderbox
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9e281904c0a8538cd9ce9f4e5fe03f943fd42581 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_site_configs-0.5.0-py3-none-any.whl.
File metadata
- Download URL: django_site_configs-0.5.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a90c18a811653dcc44e346995d0dac2bc08f063128cabb007b0f2c35a6c794ac
|
|
| MD5 |
fa288844f38609698a924be9fd74b518
|
|
| BLAKE2b-256 |
045b992caab687a758ff5258b0395398b0d53c889362843fba9b7bcd76bcd179
|
Provenance
The following attestation bundles were made for django_site_configs-0.5.0-py3-none-any.whl:
Publisher:
python-publish.yml on renderbox/django-site-configs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_site_configs-0.5.0-py3-none-any.whl -
Subject digest:
a90c18a811653dcc44e346995d0dac2bc08f063128cabb007b0f2c35a6c794ac - Sigstore transparency entry: 1397485106
- Sigstore integration time:
-
Permalink:
renderbox/django-site-configs@9e281904c0a8538cd9ce9f4e5fe03f943fd42581 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/renderbox
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9e281904c0a8538cd9ce9f4e5fe03f943fd42581 -
Trigger Event:
push
-
Statement type: