当前位置: 首页>>代码示例>>Python>>正文


Python Field.from_model方法代码示例

本文整理汇总了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 == []
开发者ID:TriOptima,项目名称:tri.form,代码行数:28,代码来源:test_forms.py

示例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
开发者ID:TriOptima,项目名称:tri.form,代码行数:10,代码来源:test_forms.py

示例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())
开发者ID:pombredanne,项目名称:tri.form,代码行数:9,代码来源:test_forms.py

示例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())
开发者ID:TriOptima,项目名称:tri.form,代码行数:9,代码来源:test_forms.py

示例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
开发者ID:pombredanne,项目名称:tri.form,代码行数:6,代码来源:test_forms.py

示例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'
开发者ID:pombredanne,项目名称:tri.form,代码行数:4,代码来源:test_forms.py


注:本文中的tri.form.Field.from_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。