当前位置: 首页>>代码示例>>Python>>正文


Python forms.HStoreField方法代码示例

本文整理汇总了Python中django.contrib.postgres.forms.HStoreField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.HStoreField方法的具体用法?Python forms.HStoreField怎么用?Python forms.HStoreField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.postgres.forms的用法示例。


在下文中一共展示了forms.HStoreField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_prep_value

# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import HStoreField [as 别名]
def get_prep_value(self, value):
        value = super(HStoreField, self).get_prep_value(value)

        if isinstance(value, dict):
            prep_value = {}
            for key, val in value.items():
                key = force_text(key)
                if val is not None:
                    val = force_text(val)
                prep_value[key] = val
            value = prep_value

        if isinstance(value, list):
            value = [force_text(item) for item in value]

        return value 
开发者ID:KimJangHyeon,项目名称:NarshaTech,代码行数:18,代码来源:hstore.py

示例2: initial_from_model

# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import HStoreField [as 别名]
def initial_from_model(cls, line, prefix=None):
        """ Builds a dict of initial form values from a Line model """
        initial = {}
        for fieldname in cls._meta.fields:
            widget = cls._meta.widgets.get(fieldname, None)
            value = getattr(line, fieldname)
            fieldkey = '%s-%s' % (prefix, fieldname) if prefix else fieldname
            # need to split MultiWidget values into each widget value
            if isinstance(widget, forms.widgets.MultiWidget):
                for i, part in enumerate(widget.decompress(value)):
                    initial['%s_%s' % (fieldkey, i)] = part
            # HStoreField gives back a dict; must serialize to json
            elif isinstance(value, dict):
                initial[fieldkey] = json.dumps(value)
            # everything else shove value into fieldname
            else:
                initial[fieldkey] = str(value)
        return initial 
开发者ID:JBEI,项目名称:edd,代码行数:20,代码来源:forms.py

示例3: get_transform

# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import HStoreField [as 别名]
def get_transform(self, name):
        transform = super(HStoreField, self).get_transform(name)
        if transform:
            return transform
        return KeyTransformFactory(name) 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:7,代码来源:hstore.py

示例4: validate

# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import HStoreField [as 别名]
def validate(self, value, model_instance):
        super(HStoreField, self).validate(value, model_instance)
        for key, val in value.items():
            if not isinstance(val, six.string_types):
                raise exceptions.ValidationError(
                    self.error_messages['not_a_string'],
                    code='not_a_string',
                    params={'key': key},
                ) 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:11,代码来源:hstore.py

示例5: formfield

# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import HStoreField [as 别名]
def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.HStoreField,
        }
        defaults.update(kwargs)
        return super(HStoreField, self).formfield(**defaults) 
开发者ID:ComputerSocietyUNB,项目名称:CodingDojo,代码行数:8,代码来源:hstore.py

示例6: validate

# 需要导入模块: from django.contrib.postgres import forms [as 别名]
# 或者: from django.contrib.postgres.forms import HStoreField [as 别名]
def validate(self, value, model_instance):
        super(HStoreField, self).validate(value, model_instance)
        for key, val in value.items():
            if not isinstance(val, six.string_types) and val is not None:
                raise exceptions.ValidationError(
                    self.error_messages['not_a_string'],
                    code='not_a_string',
                    params={'key': key},
                ) 
开发者ID:prakharchoudhary,项目名称:Scrum,代码行数:11,代码来源:hstore.py


注:本文中的django.contrib.postgres.forms.HStoreField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。