本文整理汇总了Python中tri.form.Field.from_model方法的典型用法代码示例。如果您正苦于以下问题:Python Field.from_model方法的具体用法?Python Field.from_model怎么用?Python Field.from_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tri.form.Field
的用法示例。
在下文中一共展示了Field.from_model方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_field_from_model_supports_all_types
# 需要导入模块: from tri.form import Field [as 别名]
# 或者: from tri.form.Field import from_model [as 别名]
def test_field_from_model_supports_all_types():
from django.db.models import fields
not_supported = []
blacklist = {
'AutoField',
'Field',
'BigAutoField',
'BinaryField',
'FilePathField',
'GenericIPAddressField',
'IPAddressField',
'NullBooleanField',
'SlugField',
'DurationField',
'UUIDField'
}
field_type_names = [x for x in dir(fields) if x.endswith('Field') and x not in blacklist]
for name in field_type_names:
field_type = getattr(fields, name)
try:
Field.from_model(model=Foo, model_field=field_type())
except AssertionError: # pragma: no cover
not_supported.append(name)
assert not_supported == []
示例2: test_field_from_model_blank_handling
# 需要导入模块: from tri.form import Field [as 别名]
# 或者: from tri.form.Field import from_model [as 别名]
def test_field_from_model_blank_handling():
from django.db.models import CharField
subject = Field.from_model(model=Foo, model_field=CharField(blank=False))
assert True is subject.parse_empty_string_as_none
subject = Field.from_model(model=Foo, model_field=CharField(blank=True))
assert False is subject.parse_empty_string_as_none
示例3: test_field_from_model_foreign_key
# 需要导入模块: from tri.form import Field [as 别名]
# 或者: from tri.form.Field import from_model [as 别名]
def test_field_from_model_foreign_key():
Foo.objects.create(foo=2)
Foo.objects.create(foo=3)
Foo.objects.create(foo=5)
choices = Field.from_model(FieldFromModelForeignKeyTest, 'foo_fk').choices
assert isinstance(choices, QuerySet)
assert set(choices) == set(Foo.objects.all())
示例4: test_field_from_model_many_to_many
# 需要导入模块: from tri.form import Field [as 别名]
# 或者: from tri.form.Field import from_model [as 别名]
def test_field_from_model_many_to_many():
Foo.objects.create(foo=2)
Foo.objects.create(foo=3)
Foo.objects.create(foo=5)
choices = Field.from_model(FieldFromModelManyToManyTest, 'foo_many_to_many').choices
assert isinstance(choices, QuerySet)
assert set(choices) == set(Foo.objects.all())
示例5: test_register_field_factory
# 需要导入模块: from tri.form import Field [as 别名]
# 或者: from tri.form.Field import from_model [as 别名]
def test_register_field_factory():
register_field_factory(FooField, lambda **kwargs: 7)
assert Field.from_model(RegisterFieldFactoryTest, 'foo') == 7
示例6: test_help_text_from_model
# 需要导入模块: from tri.form import Field [as 别名]
# 或者: from tri.form.Field import from_model [as 别名]
def test_help_text_from_model():
assert Form(data=Data(foo='1'), fields=[Field.from_model(model=Foo, field_name='foo')], model=Foo).validate().fields[0].help_text == 'foo_help_text'