简体   繁体   中英

Django admin site: implement a singleton for global variables?

Does anyone have experience (Django 1.x pref 1.3) with implementing a sort of singleton accessible from the admin page to expose some global variables for editing (site name, keywords, ...). I cant find anything like this and it sounds quite unbelievable!

thanks

(django-preferences is broken with 1.x)

You should avoid using singleton's as much as possible.

Are Singletons really that bad?

What is so bad about singletons?

For the rest, site name is editable in Django admin (see django.contrib.sites module).

Talking about keywords - it's bad to repeat them, thus, you better implement it in your item model (page, news article, etc).

Could you maybe give more examples of what do you need it for?

As lazerscience says, you probably want Django-dbsettings. I have a fork at Github that works with the latest Django versions.

after some playing I had dbsettings working... but with a few glitches: - Aptana doesnt recognise the import preferences as a valid reference - when I access my /settings/ page with the fields of the model I created and then save it I have a CSRF token missing or incorrect. error

NOTE: The official googlecode repository doesnt work (with 1.3), Daniel's version does instead (I guess he changed newforms -> forms etc). The way I created a new model for the settings veiw is:

from django.db import models
import dbsettings

class ImageLimits(dbsettings.Group):
        maximum_width = dbsettings.PositiveIntegerValue()
        maximum_height = dbsettings.PositiveIntegerValue()
options = ImageLimits()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM