Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep Django app settings in database, or change on-the-fly?

Does anyone have a suggestion on how to create a system that allows me to change settings on the fly? For example, I have a textarea that users can fill, and right now it has a maximum character limit of 1000. Someday I might want to change it to 500, or 2000, or something else. So I do not want to put a limit on the model itself, lest I want to go through the nightmare of backing up the DB, run syncdb, re-import DB, such a nightmare just to change a simple value. I'd rather do a check through Javascript or a views.py code on the character length.

if (length > value_stored_somewhere)
 throw error message

I thought I could just put these values in settings.py, or perhaps a separate local-settings.py, but that means if I want to change the value I would have to restart the app, right? Or I could be wrong, so please tell me if I am wrong.

I thought that the ideal way to do this would be to put the settings in the database, so administrators can change values on-the-fly without touching any .py files. I took a look at django-dbsettings but there doesn't seem to be any activity at all there.

Please give me suggestions and solutions. Thanks a lot!

like image 583
rabbid Avatar asked Apr 25 '11 02:04

rabbid


People also ask

Which is default database in settings file in Django?

By default, the configuration uses SQLite. If you're new to databases, or you're just interested in trying Django, this is the easiest choice. SQLite is included in Python, so you won't need to install anything else to support your database.


1 Answers

You are right with all your assumptions. You need to restart the app if you want to change settings (in any settings file). Right now there is no way to "change settings on the fly". There are a bunch of reusable apps outside handling so called Live Settings. Maybe you try one of these. Keep in mind that even you change settings on the fly you will not change behavior in Django (since Django or also other apps are using internal settings directly). For a custom app or project though, this is a good approach.

like image 187
Torsten Engelbrecht Avatar answered Nov 14 '22 23:11

Torsten Engelbrecht