Python django.db.models.fields 模块,BooleanField() 实例源码

我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用django.db.models.fields.BooleanField()

项目:Quiver-alfred    作者:danielecook    | 项目源码 | 文件源码
def get_django_field_map(self):
        from django.db.models import fields as djf
        return [
            (djf.AutoField, PrimaryKeyField),
            (djf.BigIntegerField, BigIntegerField),
            # (djf.BinaryField, BlobField),
            (djf.BooleanField, BooleanField),
            (djf.CharField, CharField),
            (djf.DateTimeField, DateTimeField),  # Extends DateField.
            (djf.DateField, DateField),
            (djf.DecimalField, DecimalField),
            (djf.FilePathField, CharField),
            (djf.FloatField, FloatField),
            (djf.IntegerField, IntegerField),
            (djf.NullBooleanField, partial(BooleanField, null=True)),
            (djf.TextField, TextField),
            (djf.TimeField, TimeField),
            (djf.related.ForeignKey, ForeignKeyField),
        ]
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
def get_django_field_map(self):
        from django.db.models import fields as djf
        return [
            (djf.AutoField, PrimaryKeyField),
            (djf.BigIntegerField, BigIntegerField),
            # (djf.BinaryField, BlobField),
            (djf.BooleanField, BooleanField),
            (djf.CharField, CharField),
            (djf.DateTimeField, DateTimeField),  # Extends DateField.
            (djf.DateField, DateField),
            (djf.DecimalField, DecimalField),
            (djf.FilePathField, CharField),
            (djf.FloatField, FloatField),
            (djf.IntegerField, IntegerField),
            (djf.NullBooleanField, partial(BooleanField, null=True)),
            (djf.TextField, TextField),
            (djf.TimeField, TimeField),
            (djf.related.ForeignKey, ForeignKeyField),
        ]
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
def get_django_field_map(self):
        from django.db.models import fields as djf
        return [
            (djf.AutoField, PrimaryKeyField),
            (djf.BigIntegerField, BigIntegerField),
            # (djf.BinaryField, BlobField),
            (djf.BooleanField, BooleanField),
            (djf.CharField, CharField),
            (djf.DateTimeField, DateTimeField),  # Extends DateField.
            (djf.DateField, DateField),
            (djf.DecimalField, DecimalField),
            (djf.FilePathField, CharField),
            (djf.FloatField, FloatField),
            (djf.IntegerField, IntegerField),
            (djf.NullBooleanField, partial(BooleanField, null=True)),
            (djf.TextField, TextField),
            (djf.TimeField, TimeField),
            (djf.related.ForeignKey, ForeignKeyField),
        ]
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:tumanov_castleoaks    作者:Roamdev    | 项目源码 | 文件源码
def set_boolean(instance, field):
    """ BooleanField """
    possibles = [True, False]
    possibles.extend(get_field_choices(field))
    setattr(instance, field.name, random.choice(possibles))
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:DjangoBlog    作者:0daybug    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:intel-manager-for-lustre    作者:intel-hpdd    | 项目源码 | 文件源码
def filter_fields_to_type(klass, query_dict):
    reserved_fields = ['order_by', 'format', 'limit', 'offset']

    q = QuerySet(klass)

    query = dict(query_dict)

    fields = {}
    for field in q.model._meta.fields:
        fields[field.column] = field

    # Remove the reserved fields we know about.
    for field in query.keys():
        if field in reserved_fields:
            del query[field]

    # This will error if it find an unknown field and cause the standard tasty pie query to run.
    for field in query.keys():
        try:
            field_type = type(fields[field])
            value = query[field]

            if field_type == django_fields.AutoField or field_type == django_fields.IntegerField:
                value = int(value)
            elif field_type == django_fields.BooleanField:
                value = (value.lower() == 'true')

            query[field] = value
        except KeyError:
            pass

    return query


# monkey-patch ResourceOptions to have a default-empty readonly list
项目:wanblog    作者:wanzifa    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:tabmaster    作者:NicolasMinghetti    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:trydjango18    作者:lucifer-yqh    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:trydjango18    作者:wei0104    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:ims    作者:ims-team    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:django-open-lecture    作者:DmLitov4    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:travlr    作者:gauravkulkarni96    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def clean(self):
        super(PagePermissionInlineAdminForm, self).clean()
        for field in self.Meta.model._meta.fields:
            if not isinstance(field, BooleanField) or not field.name.startswith('can_'):
                continue
            name = field.name
            self.cleaned_data[name] = self.cleaned_data.get(name, False)
        can_add = self.cleaned_data['can_add']
        can_edit = self.cleaned_data['can_change']
        # check if access for childrens, or descendants is granted
        if can_add and self.cleaned_data['grant_on'] == ACCESS_PAGE:
            # this is a missconfiguration - user can add/move page to current
            # page but after he does this, he will not have permissions to
            # access this page anymore, so avoid this
            raise forms.ValidationError(_("Add page permission requires also "
                                          "access to children, or descendants, otherwise added page "
                                          "can't be changed by its creator."))

        if can_add and not can_edit:
            raise forms.ValidationError(_('Add page permission also requires edit page permission.'))
            # TODO: finish this, but is it really required? might be nice to have

        # check if permissions assigned in cms are correct, and display
        # a message if not - correctness mean: if user has add permission to
        # page, but he doesn't have auth permissions to add page object,
        # display warning
        return self.cleaned_data
项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def save(self, commit=True):
        """
        Makes sure the boolean fields are set to False if they aren't
        available in the form.
        """
        instance = super(PagePermissionInlineAdminForm, self).save(commit=False)
        for field in self._meta.model._meta.fields:
            if isinstance(field, BooleanField) and field.name.startswith('can_'):
                setattr(instance, field.name, self.cleaned_data.get(field.name, False))
        if commit:
            instance.save()
        return instance
项目:logo-gen    作者:jellene4eva    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:liberator    作者:libscie    | 项目源码 | 文件源码
def output_field(self):
        return fields.BooleanField()
项目:gmail_scanner    作者:brandonhub    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:djanoDoc    作者:JustinChavez    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:CSCE482-WordcloudPlus    作者:ggaytan00    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:tissuelab    作者:VirtualPlants    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:producthunt    作者:davidgengler    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:geekpoint    作者:Lujinghu    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:django-next-train    作者:bitpixdigital    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:LatinSounds_AppEnviaMail    作者:G3ek-aR    | 项目源码 | 文件源码
def output_field(self):
        return fields.BooleanField()
项目:DjangoZeroToHero    作者:RayParra    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:Roboism    作者:markroxor    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )
项目:django-wechat-api    作者:crazy-canux    | 项目源码 | 文件源码
def test_builtin_fields(self):
        self.assertEqual(
            views.get_readable_field_data_type(fields.BooleanField()),
            _('Boolean (Either True or False)')
        )