In my application, I set one configuration in my database (lets say buffer_radius) that is not going to change very frequently. I want to set one constant BUFFER_RADIUS in Django so that every-time Django restarted/redeployed, the value of this constant set to buffer_radius. I want to do this to minimize database call.
Put it the settings.py and you can use Django-constance if you want your admins to change the value from Django Admin.
Related
I am building a django based backend.
There are some very important constants (or you can say data) which defines the functioning of the whole project.
I want to store this information in the database so that anyone with admin permission can update those constants via an api call.
I could store those constants in setting.py file but then I have to edit the python file every time I update it. I want a non technical person be able to update the data via some web form.
One thing I can do is make a database query every time I use those data.
Or is there is some concept of local storage in django like cookies.
so whats the best policy
Is there a problem to change one of the settings when django is running?
For example, I'd like to change REGISTRATION_OPEN from the django-registration app from False to True when it is live.
I do not want to stop the server to change this value.
Is there a cache that would prevent the new value to be used?
Should I rather consider a table to store settings that can be changed when it is live?
Thanks
Django Livesettings is an excellent option: http://django-livesettings.readthedocs.org/en/latest/about.html
I have Django project with my own app. This app has only two models. I need configure some options specific for this app, but in default Django admin panel.
I was thinking to create a model for example: SettingsApp and create one entry with my settings, but in admin panel, user can be add other entries or delete existing entry and app will not work. How to do it?
You should take a look at:
https://github.com/jqb/django-settings
and check if it fits well for you.
This work for my settings model:
class SettingsAdmin(admin.ModelAdmin):
def has_add_permission(self, request):
return False
def has_remove_permission(self, request):
return False
I recommend you to take a look at application django-livesettings from here. As said in documentation:
Django-Livesettings is a project split from the Satchmo Project. It
provides the ability to configure settings via an admin interface,
rather than by editing settings.py. In addition, livesettings allows
you to set sane defaults so that your site can be perfectly functional
without any changes. Livesettings uses caching to make sure this has
minimal impact on your site’s performance.
Finally, if you wish to lock down your site and disable the settings,
you can export your livesettings and store them in your settings.py.
This allows you have flexibility in deciding how various users
interact with your app.
Livesettings supports several types of input choices:
Boolean
Decimal
Duration
Float
Integer
Positive Integer
String
Long string
Multiple strings
Long multiple strings
Module values
Password
Livesettings has been used for many years in the satchmo project and
is considered stable and production ready.
How can one store, retrieve and allow the user to change the settings of a project or an app? A constant in settings.py is not good enough, as I want some users to be able to change the value of the setting. A way to present these in the admin interface would be optimal.
If it's via an admin interface then using the database sounds like a sure bet. Check out this similar looking question on StackOverflow.
Django can make use of multiple database engines at the same time. My problem is the queries always refer to the default database. I want the queries for a different app to go to a different database instead of the default database.
How do I solve this?
Django supports multiple databases and you can use the "Automatic database routing" to do what you want.
I think that it's enough powerful for your needs but if you need more flexibility, you can "Manually selecting a database"