當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。