Skip to main content

django-db-settings

django-db-settings is a Django app to save your configuration in cacheable DB objects that are easily defined like classes.

Quick start

  1. Install django-db-settings using pip:

    pip install django-db-settings

  2. Add “settings” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'settings',
    ]
  3. Include the settings URLconf in your project urls.py like this:

    path('settings/', include('settings.urls')),
  4. Run python manage.py migrate to create the settings models.

  5. Start the development server and visit http://127.0.0.1:8000/admin/ to setup your app settings (you’ll need the Admin app enabled).

  6. Visit http://127.0.0.1:8000/settings/?setting=YOUR_SETTING to get the objects related to that specific setting (JSON).

  7. Find the REFRESH SETTINGS button with in Value model change list page. This project uses TTL based cache, which can be configured by adding the following setting:

    • SETTINGS_CACHE_MAXSIZE: To set the maximum size of total items in the cache. By default set to 100.

    • SETTINGS_CACHE_TTL: To set the Time To Live of the cache items. By default set to 3600 seconds (1 hour).

Basic Usage

django-db-settings saves your settings in a flexible model. To create a setting follow these steps:

  1. Create a setting in model Setting, it will act like the class that will group a set of settings. e.g., product type

  2. Define the attributes of this Setting by adding them in model Field. You can set each as public or private. e.g., title, description, code.

  3. Add Setting instances in model Instance. They will act as the objects of the setting class. e.g., saving, credit card, loan.

  4. Finally, add values in model Value for every instance guided by the fields defined for Setting. e.g., for saving instance, values are title: Saving account, description: Saves you money, code: S001.

After adding all values, you will be able to retrieve all those which fields are public by going to http://127.0.0.1:8000/settings/?setting=product%20type. It returns a JSON object:

{“saving”: {“title”: “Saving account”, “description”: “Save your money with us!”}, “credit card”: {“title”: “Credit Card”, “description”: “Get the best from our Credit Card”}, “loan”: {“title”: “Loan”, “description”: “We loan you the money you need”}}

TIP: You can use the same settings internally by calling method get_setting in module settings.business:

>>> get_setting('product type')
{'saving': {'title': 'Saving account', 'description': 'Save your money with us!'}, 'credit card': {'title': 'Credit Card', 'description': 'Get the best from our Credit Card'}, 'loan': {'title': 'Loan', 'description': 'We loan you the money you need'}}

Internally, you can set parameter include_non_public=True to retrieve private fields also:

>>> get_setting('product type', include_non_public=True)
{'saving': {'title': 'Saving account', 'description': 'Save your money with us!', 'code': 'S-001'}, 'credit card': {'title': 'Credit Card', 'code': 'C-001', 'description': 'Get the best from our Credit Card'}, 'loan': {'title': 'Loan', 'description': 'We loan you the money you need', 'code': 'L-001'}}

Call method clear_settings_cache from the same package to clear the cache and refresh the global settings.

Release files for django-db-settings 1.2.1

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-db-settings 1.2.1
File Size Uploaded
django-db-settings-1.2.1.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-db-settings 1.2.1
File Interpreter ABI Platform
django_db_settings-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / django-db-settings-1.2.1.tar.gz

Download URL django-db-settings-1.2.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b3e5e4f114388e1f937c3740e9550d520b6a8a147f124d53ceae147797a8928f
BLAKE2b-256 checksum
How to use checksums
7863ce757d7eb7d59d82aa468e06adf04ffff900673a8f12365672ff8f0d68a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

Release files / django_db_settings-1.2.1-py3-none-any.whl

Download URL django_db_settings-1.2.1-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a20f756ec30d5796bfd790e87b31e9bf6c295bcf024a64d9f5972acc334e552d
BLAKE2b-256 checksum
How to use checksums
a1a6d966db2691ac625165717e836fb8fe6995174a9a54d32efcf8dff0e058db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

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