0

Django Singletons with django-solo for storing site/device settings

Oftenly, websites or Raspberry Pi devices with Django interfaces have some settings, that only exist once and don’t need to be instantiated. To handle this elegantly, one can use the neat Django Singleton module django-solo.

Installation
Enter

Usage
Here is the model from the models.py of a countdown which stores the remaining seconds and if the countdown is running. This data is used to reset the browser functionality in case of reload or reboot.

In your view.py, you can now import the model and use the singleton:

app is the Django app which uses the singleton. get_solo() gives back the only instance of the singleton or creates one if it doesn’t exist.

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.

Comment

Time limit is exhausted. Please reload CAPTCHA.