當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.NullBooleanField方法代碼示例

本文整理匯總了Python中django.forms.NullBooleanField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.NullBooleanField方法的具體用法?Python forms.NullBooleanField怎麽用?Python forms.NullBooleanField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms的用法示例。


在下文中一共展示了forms.NullBooleanField方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_nullbooleanfield_changed

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def test_nullbooleanfield_changed(self):
        f = NullBooleanField()
        self.assertTrue(f.has_changed(False, None))
        self.assertTrue(f.has_changed(None, False))
        self.assertFalse(f.has_changed(None, None))
        self.assertFalse(f.has_changed(False, False))
        self.assertTrue(f.has_changed(True, False))
        self.assertTrue(f.has_changed(True, None))
        self.assertTrue(f.has_changed(True, False))
        # HiddenInput widget sends string values for boolean but doesn't clean them in value_from_datadict
        self.assertFalse(f.has_changed(False, 'False'))
        self.assertFalse(f.has_changed(True, 'True'))
        self.assertFalse(f.has_changed(None, ''))
        self.assertTrue(f.has_changed(False, 'True'))
        self.assertTrue(f.has_changed(True, 'False'))
        self.assertTrue(f.has_changed(None, 'False')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_nullbooleanfield.py

示例2: _check_null

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def _check_null(self, **kwargs):
        if getattr(self, 'null', False):
            return [
                checks.Error(
                    'BooleanFields do not accept null values.',
                    hint='Use a NullBooleanField instead.',
                    obj=self,
                    id='fields.E110',
                )
            ]
        else:
            return [] 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:14,代碼來源:__init__.py

示例3: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def __init__(self, *args, **kwargs):
        kwargs['null'] = True
        kwargs['blank'] = True
        super(NullBooleanField, self).__init__(*args, **kwargs) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:6,代碼來源:__init__.py

示例4: deconstruct

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def deconstruct(self):
        name, path, args, kwargs = super(NullBooleanField, self).deconstruct()
        del kwargs['null']
        del kwargs['blank']
        return name, path, args, kwargs 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:__init__.py

示例5: get_internal_type

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def get_internal_type(self):
        return "NullBooleanField" 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:4,代碼來源:__init__.py

示例6: get_prep_lookup

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def get_prep_lookup(self, lookup_type, value):
        # Special-case handling for filters coming from a Web request (e.g. the
        # admin interface). Only works for scalar values (not lists). If you're
        # passing in a list, you might as well make things the right type when
        # constructing the list.
        if value in ('1', '0'):
            value = bool(int(value))
        return super(NullBooleanField, self).get_prep_lookup(lookup_type,
                                                             value) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:11,代碼來源:__init__.py

示例7: formfield

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def formfield(self, **kwargs):
        defaults = {
            'form_class': forms.NullBooleanField,
            'required': not self.blank,
            'label': capfirst(self.verbose_name),
            'help_text': self.help_text}
        defaults.update(kwargs)
        return super(NullBooleanField, self).formfield(**defaults) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:10,代碼來源:__init__.py

示例8: formfield

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def formfield(self, **kwargs):
        defaults = {'form_class': forms.NullBooleanField}
        defaults.update(kwargs)
        return super().formfield(**defaults) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:6,代碼來源:__init__.py

示例9: formfield

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def formfield(self, **kwargs):
        if self.choices:
            include_blank = not (self.has_default() or 'initial' in kwargs)
            defaults = {'choices': self.get_choices(include_blank=include_blank)}
        else:
            form_class = forms.NullBooleanField if self.null else forms.BooleanField
            # In HTML checkboxes, 'required' means "must be checked" which is
            # different from the choices case ("must select some value").
            # required=False allows unchecked checkboxes.
            defaults = {'form_class': form_class, 'required': False}
        return super().formfield(**{**defaults, **kwargs}) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:13,代碼來源:__init__.py

示例10: get_prep_value

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import NullBooleanField [as 別名]
def get_prep_value(self, value):
        value = super(NullBooleanField, self).get_prep_value(value)
        if value is None:
            return None
        return self.to_python(value) 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:7,代碼來源:__init__.py


注:本文中的django.forms.NullBooleanField方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。