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.
Related
Is there a way to deploy Django Admin and your main application separately, though both of them sharing the same Models / Business logic services.
I come from Grails background where you can create a plugin which can hold your Entities and common business logic and that plugin can be utilized by other application deployed and scaled separately though using the same Database. You don't have to repackage your plugin again for every change rather its just sibling folder to your other projects.
Can I achieve something similar with Django?
Assuming a typical setup, in order to be useful Django Admin needs access to project's apps and their models.
So a setup that you've described would require at least:
simple URLconf with just Django Admin
models and their Admin bindings for all apps that need Admin
settings with database credentials
Even if your models and Admin bindings are not dependent on other parts of the codebase,
extracting the above components to a separate project and then keeping everything
in sync sounds pretty hard.
Summarizing: I would say it's hard but possible if it's something that you really need,
but Django Admin hasn't been designed with such use case in mind.
Django admin is actually separate from the main application by placing it on its own url. Even if they know the admin url, users cannot log in to the site's admin unless they have already been assigned Staff status via the admin. You can set the admin prefix to anything you want, so if you want to "hide" the admin login page, just make it something long and random (good for security too), and basically no one but those you tell will even know where the admin site can be found.
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.
I want to use Django for a web application I'm building that will have an admin panel. I know that you need to just activate the admin app and you're ready to go. However, I would like to have a custom panel, I mean, I want to design the layout myself, I want to add menus and forms for the admin to insert new data in the database etc. Is it possible? or I should write a similar application that will have such features?
For more control over the layout (custom menus etc.) you should check django-admin-tools.
And if you take a look at Django's docs you'll learn that you can easily tweak and override most parts of the admin. For example here is a demonstration on how to use a custom form:
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin
So the admin is pretty customizable. But the question if you should build your own app or reuse the admin depends pretty much on your specific needs. At least make sure you know in which directions the admin can be easily bend.
The sole purpose for Django's admin is to allow you to manipulate (add/edit/remove) data in your database. I think you should at least try to check what the admin is capable of before trying to reinvent the wheel. You'll soon discover the level of complex insight the admin allows you to have. Then you'll discover that making it yourself is unnecessary excess of work and you'll end up with modifying a couple of admin-templates and CSS styles.
Yes, you can customize Django Admin Panel, Django provides some sort of customization for showing database tables structure from their own, for that you can follow DJANGO ADMIN SITE DOC , it will really help you.
For the customizations beyond the Django admin site settings, you can customize admin panel add manual layout, by adding manual detailing in Django template files which are stored in Django environment, django/django/contrib/admin/templates/admin/index.html of your current Django version. You can update its HTML, CSS, and JS according to need.
Has anyone run into an idea of a "settings app" for a django project?
It's a set of application variables set by an administrator (not developer, so settings.py fails) using admin panel.
Are there any apps ready to use?
edit
I probably didn't state my question clear. I don't mean editing the things like connection settings, rather things like "file size limit".
There is a very nice app that does this, called django-dbsettings. The official repo hasn't been updated in years, but I have an up-to-date fork on my github page.
The question is how would you store the settings.
Cause... if you store the settings in the database it will be troublesome since most of the code will already be initialized (using the settings before that) before you have a database connection.
If it's the filesystem that means you're going to have to include a Python file that's being modified by your webserver which sounds like a huge security risk to me.
So... in my opinion, it could be done but I would vote against it since it's dangerous. If things should be configurable from the web, implement that in the app :)
It sounds a bit like you're asking "how does an administrator change the settings (like database connection parameters) without changing settings.py?"
If your admin isn't familiar enough with python to change the settings.py file directly, you might consider giving the admin a simpler file to edit, perhaps a config file that you loaded from settings.py. Then all your admin has to do is edit the config file and restart the server.
This has an added benefit that you can limit the config file to only those parameters which your admin would need to mess with (like database connection parameters).
(Another option would be to get a better admin ...)
Is there a good way provide user configurable app settings in Django admin?
Basically I would like to have a nice forms where site owner can easily edit such one off information as his contact information, front page text content, etc. Sort of like a normal admin interface of a model, but limited to only one undeletable item in the model.
I think django constance is the way to go. Alive and compatible with django 1.4.
The third-party project django-dbsettings is ideal for this.
I looked at dbsettings and liked some of what I saw, but I really wanted a more centralized, organized system. So I built django-appsettings. Enjoy :)
Found this: django-livesettings