Skip to main content

django-setty

Django-Setty allows you to dynamically change settings inside the Django Admin Console. The app provides both a database and a cache backend for storing and retrieving your settings.

Coverage Status

Requirements

  • Python 3.6+
  • Django 2.0+

Continuous integration currently tests Django >= v2.

Installation

pip install django-setty

Django Configuration

Add setty to the list of INSTALLED_APPS in your Django settings:

INSTALLED_APPS = [
    ...
    'setty'
]

Create the Setty database table by running

python manage.py migrate

Specify the backend to use using the SETTY_BACKEND setting. The valid backend values are 'DatabaseBackend' and 'CacheBackend'.

'DatabaseBackend' always accesses the database when retrieving settings.

'CacheBackend' only accesses the database if the item is not in the cache, and caches the value once retrieved.

Define the length of time settings should be cached for using the SETTY_CACHE_TTL setting. The default cache TTL is one hour.

SETTY_BACKEND = 'CacheBackend'
SETTY_CACHE_TTL = 60  # 60 seconds

Usage Examples

Open the Django admin console at /admin and open Setty Settings. Here, you will see the list of all settings defined in Setty.

To add a new setting, click the add button.

Enter the setting name, type (String, Integer, Float, Boolean, List, Dictionary) and the value. Note, the List and Dict data type expect the data to be in the JSON format e.g. {"a": 1, "b": 2} and [1, 2, 3].

Once settings have been created, you will be able to access these in your code.

from setty import config

assert config.my_integer == 10

If the setting does not exist in the database, the value defined in the setting SETTY_NOT_FOUND_VALUE will be used. If this is not set, None will be returned.

Setty can be used inside Django templates by adding 'setty.context_processors.setty_settings' to the TEMPLATE_CONTEXT_PROCESSORS setting and accessing it via the setty key.

The value of a setting can also be updated by using the syntax:

from setty import config

config.my_integer = 100

Note: Only settings that already exist in the database can be updated. New settings cannot be added this way.

Loading all settings into the Cache

If you use the CacheBackend backend, you can easily load all settings into the Cache. This is useful if you want to cache all settings when you start up your app.

from setty.backend import CacheBackend
CacheBackend().load_all_settings_into_cache()

Similar Projects

Release files for django-setty 3.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-setty 3.2.2
File Size Uploaded
django-setty-3.2.2.tar.gz 15.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-setty 3.2.2
File Interpreter ABI Platform
django_setty-3.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 29.4 kB

Release files / django-setty-3.2.2.tar.gz

Download URL django-setty-3.2.2.tar.gz
Size 15.0 kB
Tags Source
SHA-256 checksum
How to use checksums
88575980430909ca789b883d5b474b4ad87217c7493506743edf756502d58c74
BLAKE2b-256 checksum
How to use checksums
43a6cf7945a62833875275fe0f1ebdb7b29208b7b620f4298f14b5e80ef3360c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Release files / django_setty-3.2.2-py3-none-any.whl

Download URL django_setty-3.2.2-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87bbaeeefe0e682171ff5eddf61278566af731755a9a3c777d1cf1589626df47
BLAKE2b-256 checksum
How to use checksums
e01f90938102e2da8c4addcc92b271a1e18eae622a7a727163327dc7aedc4f5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

Release history Release notifications | RSS feed

This release

3.2.2 This release

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page