当前位置: 首页>>代码示例>>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;未经允许,请勿转载。