本文整理汇总了Python中django.db.models.fields.BooleanField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.BooleanField方法的具体用法?Python fields.BooleanField怎么用?Python fields.BooleanField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.fields
的用法示例。
在下文中一共展示了fields.BooleanField方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_django_field_map
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
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),
]
示例2: build_schema_from_model
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def build_schema_from_model(model):
field_mappings = {
model_fields.BigIntegerField: "INTEGER",
model_fields.CharField: "STRING",
model_fields.DateField: "DATE",
model_fields.FloatField: "FLOAT",
model_fields.DecimalField: "NUMERIC",
model_fields.IntegerField: "INTEGER",
model_fields.BooleanField: "BOOLEAN",
model_fields.NullBooleanField: "BOOLEAN",
model_fields.TextField: "STRING",
related_fields.ForeignKey: "INTEGER",
related_fields.OneToOneField: "INTEGER",
}
fields = [
(f.name, field_mappings[type(f)])
for f in model._meta.fields
if not f.auto_created
]
return build_schema(*fields)
示例3: _build_search_filter
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def _build_search_filter(cls, field_name):
if field_name == "bnf_code":
return _build_search_filter_bnf_code_prefox()
field = cls._meta.get_field(field_name)
builder = {
ForeignKey: _build_search_filter_fk,
ManyToOneRel: _build_search_filter_rev_fk,
OneToOneRel: _build_search_filter_rev_fk,
fields.CharField: _build_search_filter_char,
fields.DateField: _build_search_filter_date,
fields.BooleanField: _build_search_filter_boolean,
fields.DecimalField: _build_search_filter_decimal,
}[type(field)]
search_filter = builder(field)
search_filter["id"] = field_name
return search_filter
示例4: test_builtin_fields
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def test_builtin_fields(self):
self.assertEqual(
views.get_readable_field_data_type(fields.BooleanField()),
_('Boolean (Either True or False)')
)
示例5: get_json_data
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def get_json_data(self, **kwargs):
qs = kwargs.get('qs')
if qs is None:
qs = self.get_queryset()
extra_json_fields = list(self.extra_json_fields)
extra_json_fields.append('pk')
extra_json_fields += list(self.annotate.keys())
if not self.json_fields:
self.json_fields = [f.name for f in self.model._meta.concrete_fields]
if 'columns' in self.request.GET:
columns = self.request.GET['columns'].split(',')
else:
columns = self.json_fields + extra_json_fields
data = list(qs.annotate(**self.annotate).values(*columns))
# TODO: consider replace none_to_bool - either use default=False or update jqWidgets
bool_fields = [i.name for i in self.model._meta.fields
if isinstance(i, django_fields.BooleanField)]
for row in data:
row.update((k, False) for k, v in row.items() if v is None and k in bool_fields)
if not kwargs.get('keep_tags'):
row.update((k, v.replace("<", "<").replace(">", ">"))
for k, v in row.items() if isinstance(v, str))
return data
示例6: output_field
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def output_field(self):
return fields.BooleanField()
示例7: test_boolean_constraints
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def test_boolean_constraints(self):
"""Boolean fields have check constraints on their values."""
for field in (BooleanField(), NullBooleanField(), BooleanField(null=True)):
with self.subTest(field=field):
field.set_attributes_from_name('is_nice')
self.assertIn('"IS_NICE" IN (0,1)', field.db_check(connection))
示例8: test_builtin_fields
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def test_builtin_fields(self):
self.assertEqual(
views.get_readable_field_data_type(fields.BooleanField()),
'Boolean (Either True or False)'
)
示例9: _build_lookup_key
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def _build_lookup_key(cls, field_name, operator):
field = cls._meta.get_field(field_name)
builder = {
ForeignKey: _build_lookup_fk,
ManyToOneRel: _build_lookup_rev_fk,
OneToOneRel: _build_lookup_rev_fk,
fields.CharField: _build_lookup_char,
fields.DateField: _build_lookup_date,
fields.BooleanField: _build_lookup_boolean,
fields.DecimalField: _build_lookup_decimal,
}[type(field)]
return builder(cls, field_name, operator)
示例10: _build_row
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def _build_row(obj, field):
value = getattr(obj, field.name)
if value is None:
return
if field.name == "invalid" and not value:
return
if isinstance(field, ForeignKey):
related_model = field.related_model
if related_model in cls_to_obj_type:
obj_type = cls_to_obj_type[related_model]
link = reverse("dmd_obj", args=[obj_type, value.id])
text = getattr(value, related_model.name_field)
return {
"key": related_model._meta.verbose_name,
"value": text,
"link": link,
}
try:
value = value.descr
except AttributeError:
value = value.nm
elif isinstance(field, fields.BooleanField):
value = {True: "✓", False: "✗"}.get(value)
return {"key": field.help_text, "value": value}
示例11: import_model
# 需要导入模块: from django.db.models import fields [as 别名]
# 或者: from django.db.models.fields import BooleanField [as 别名]
def import_model(self, model, elements):
"""Import model instances from list of XML elements."""
model.objects.all().delete()
boolean_field_names = [
f.name
for f in model._meta.fields
if isinstance(f, django_fields.BooleanField)
]
table_name = model._meta.db_table
column_names = [
f.db_column or f.name
for f in model._meta.fields
if not isinstance(f, django_fields.AutoField)
]
sql = "INSERT INTO {} ({}) VALUES ({})".format(
table_name, ", ".join(column_names), ", ".join(["%s"] * len(column_names))
)
values = []
for element in elements:
row = {}
for field_element in element:
name = field_element.tag.lower()
if name == "desc":
# "desc" is a really unhelpful field name if you're writing
# SQL!
name = "descr"
elif name == "dnd":
# For consistency with the rest of the data, we rename
# "dnd" to "dndcd", as it is a foreign key field.
name = "dndcd"
value = field_element.text
row[name] = value
for name in boolean_field_names:
row[name] = name in row
values.append([row.get(name) for name in column_names])
with connection.cursor() as cursor:
cursor.executemany(sql, values)