Skip to main content

Master Settings is a simple Django app to have simple typed settings in django app with type validation.

Installation & Setup

  1. Install using pip

$> pip install django-ma-settings
  1. add ‘ma-settings’ into INSTALLED_APPS

INSTALLED_APPS = (
    # ...
    'ma_settings',
    # ...
)
  1. define MASTER_SETTINGS dict with your settings definition

template:

MASTER_SETTINGS = {
    '(setting_name)':{
        'type' : '(setting_type)',
        'display_name': '(displayed name)', #optional
        'default': (default value), # optional
        'options': (choice options), # optional
        'model': (foreign model), # optional, use only when foreign type is chosen
    }
}

example:

MASTER_SETTINGS = {
    'max_email_size_kb': {
        'type': 'integer',
        'display_name': 'Max email size(kb)',
        'default': 400,
    },
    'text_color': {
        'type': 'choices',
        'display_name': 'Text color',
        'options': ['White', 'Black', 'Red', 'Blue'],
        'default': 'White',
    },
    'our_rate': {
        'type': 'float',
        'display_name': 'Our rate',
        'default': 1.0,
    },
    'email_from': {
        'type': 'string'
        'display_name': 'Email from',
    },
    'Default client': {
        'type': 'foreign',
        'model': 'my_app.Client'
    }
}
  1. define BASE_SETTINGS_TEMPLATE_NAME

BASE_SETTINGS_TEMPLATE_NAME = "template_name.html"

#  Template file must contain empty {% block settings %}
  1. in urls.py add include(‘ma_settings.urls’)

url(r'^settings/', include('ma_settings.urls')),

#  Use url name 'master_settings_home' to access settings page

{% url 'master_settings_home' %}
  1. Run commands to initialize settings

$> python manage.py syncdb
$> python manage.py init_settings

Using

To get setting use

from ma_settings import master_settings
master_settings.get('setting_name', default='default')

To set new value:

master_settings.set('setting_name', [value|model_instance])

To check if setting exists:

master_settings.exists('setting_name')

Updating settings definition

After updating settings definition in settings.py run this command to update settings

python manage.py init_settings

Metadata

Release files for django-ma-settings 1.0.9

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-ma-settings 1.0.9
File Size Uploaded Provenance
django-ma-settings-1.0.9.tar.gz 7.5 kB Without provenance Details

Release files / django-ma-settings-1.0.9.tar.gz

Download URL django-ma-settings-1.0.9.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
82a4c367ac31fad89e79998f6383dc994a121c2067e749a94dc2cb708b7e2075
BLAKE2b-256 checksum
How to use checksums
1f3f906638b2c6241bf73f602ba13eb76370e1b67772cc8eab5d2222a6778e71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-ma-settings 1.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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