本文整理汇总了Python中models.Setting.value方法的典型用法代码示例。如果您正苦于以下问题:Python Setting.value方法的具体用法?Python Setting.value怎么用?Python Setting.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Setting
的用法示例。
在下文中一共展示了Setting.value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __setattr__
# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import value [as 别名]
def __setattr__(self, name, value):
if name in ('_vals', '_name', '_appname', '_verbose_name', '_readonly', '_cache_prefix', '_main'):
return object.__setattr__(self, name, value)
if self._readonly:
raise AttributeError, 'settings group %s is read-only' % self._name
if not name in self._vals:
raise AttributeError, 'setting "%s" not found'%name
if not has_db:
raise SettingsException, "no database -- settings are immutable"
self._vals[name].initial = self._vals[name].clean(value)
try:
setting = Setting.objects.get(app = self._appname,
site = Site.objects.get_current(),
class_name = self._name,
key = name)
except Setting.DoesNotExist:
setting = Setting(site = Site.objects.get_current(),
app = self._appname,
class_name = self._name,
key = name)
serialized = value
if hasattr(self._vals[name].widget, '_format_value'):
serialized = self._vals[name].widget._format_value(value)
serialized = force_unicode(serialized)
setting.value = serialized
setting.save()
if appsettings.USE_CACHE:
cache.set(self._cache_prefix+name, value)
if self._main:
setattr(django_settings, name, value)
示例2: set_value
# 需要导入模块: from models import Setting [as 别名]
# 或者: from models.Setting import value [as 别名]
def set_value(self, key, value):
setting = Setting.query.filter(Setting.key == key).first()
if setting is None:
setting = Setting(key,'')
db.session.add(setting)
# self.logger.debug('setting {0} to {1}'.format(key, value))
setting.value = value
db.session.commit()