Skip to main content

A Django app to save app settings in DB as classes.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-db-settings-1.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

django_db_settings-1.1.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file django-db-settings-1.1.0.tar.gz.

File metadata

  • Download URL: django-db-settings-1.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for django-db-settings-1.1.0.tar.gz
Algorithm Hash digest
SHA256 81f7fde7d2c23e3db588ef9042abdcf8976fca88a7b601990264aabe4f128978
MD5 ecdac7d23d8d58d89121ae60ad5efd87
BLAKE2b-256 43ad3b5ea9a44b4061a9474796efdbd49309317f89ba677e19c03b9f0f3cff39

See more details on using hashes here.

File details

Details for the file django_db_settings-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_db_settings-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for django_db_settings-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33791dc9c1ef9d3591dbd61ca30f82f5ad5c2d17249f4b2b85a49ce5769b5473
MD5 907739a7983319ebd0ba0d98f486ea09
BLAKE2b-256 b90eb4bfc7bc5e26a0ea72285a84dca3baa957ecb16c608db8716c2af380efb7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page