Search code examples
pythondjangosingletonsettingssingle-instance

Django "Singleton model" to store user settings


I am building a web app with Django. I would like to be able to store final user settings for my app. For now I am using a model Settings that contains all what I need for the app.
It seems ok but I don't think that's the right way to do it because I could have a second row in my database and I don't want it.
I though about using a file but it is not as easy to manage as a table in a database.

Could someone help me with that please ?

Thank you ! :)

Louison


Solution

  • If I understand your question correctly, you're interested in managing settings for your django app through an editable, easy to update interface.

    A popular existing approach to this is implemented by django-constance. It can use your database or redis to store the settings, and it makes them editable through the django admin. You can look at the documentation here.

    django-constance admin example

    Ultimately, the approach of using a database table to store configuration settings is fine. The issue of having one row can feel odd though, so django-constance's approach is to use a key/value design where each individual configuration key has its own row in the table.