views:

51

answers:

3

I would like to create a single page in the admin site of django where I can change some global variables of the website (title of the website, items in the navigation menu, etc). At the moment I have them coded as context processors but I would like to make them editable. Something similar to what happens in WordPress.

Is this possible?

  • I can store the data in the databse, but can I have a link in the admin site that goes straight to the first document record and doesnt allow the creation of multiple records (they wouldnt make sense)
  • Instead of creating a model in the database, would it be possible to change some context_processor from the admin site (I think this would be best)
A: 

This sounds like what the sites framework is intended to help with.

http://docs.djangoproject.com/en/dev/ref/contrib/sites/

"It’s a hook for associating objects and functionality to particular Web sites, and it’s a holding place for the domain names and “verbose” names of your Django-powered sites."

The docs make it sound like it's only good for multiple sites, but it's a great place to put stuff in a single-site-per-django model too.

Paul McMillan
+1  A: 

There's an app called django-values that allows you storing of specific settings in the database.

lazerscience
+1  A: 

django-preferences does exactly what you are looking for. The implementation is a bit hacky (particularly the setting of module on the model class to trick Django into thinking it was loaded from a different app), but it works.

Carl Meyer
hey thanks for the reply! looks awesome but I can't get it working... I put the package in the my site-packages folder and then added the 'preferences' to the INSTALLED_APP and the (r'^admin/', include('preferences.urls')), to the urls.py. I tried to create a simple module like the one suggested but I run into an error when I try to import the class 'from preferences.model import Preferences' as it says it can't find the Preferences module. Any idea? Im still not very good with Django... THANKS
Matt Jakob
I think there's a typo in the README. It should be "from preferences.models import Preferences" - note the plural "models."
Carl Meyer
I thought that but no... it still throws the error
Matt Jakob