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


Python orm.model_form方法代码示例

本文整理汇总了Python中wtforms.ext.django.orm.model_form方法的典型用法代码示例。如果您正苦于以下问题:Python orm.model_form方法的具体用法?Python orm.model_form怎么用?Python orm.model_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wtforms.ext.django.orm的用法示例。


在下文中一共展示了orm.model_form方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: model_fields

# 需要导入模块: from wtforms.ext.django import orm [as 别名]
# 或者: from wtforms.ext.django.orm import model_form [as 别名]
def model_fields(model, only=None, exclude=None, field_args=None, converter=None):
    """
    Generate a dictionary of fields for a given Django model.

    See `model_form` docstring for description of parameters.
    """
    converter = converter or ModelConverter()
    field_args = field_args or {}

    model_fields = ((f.attname, f) for f in model._meta.fields)
    if only:
        model_fields = (x for x in model_fields if x[0] in only)
    elif exclude:
        model_fields = (x for x in model_fields if x[0] not in exclude)

    field_dict = {}
    for name, model_field in model_fields:
        field = converter.convert(model, model_field, field_args.get(name))
        if field is not None:
            field_dict[name] = field

    return field_dict 
开发者ID:snverse,项目名称:Sci-Finder,代码行数:24,代码来源:orm.py

示例2: model_form

# 需要导入模块: from wtforms.ext.django import orm [as 别名]
# 或者: from wtforms.ext.django.orm import model_form [as 别名]
def model_form(model, base_class=Form, only=None, exclude=None, field_args=None, converter=None):
    """
    Create a wtforms Form for a given Django model class::

        from wtforms.ext.django.orm import model_form
        from myproject.myapp.models import User
        UserForm = model_form(User)

    :param model:
        A Django ORM model class
    :param base_class:
        Base form class to extend from. Must be a ``wtforms.Form`` subclass.
    :param only:
        An optional iterable with the property names that should be included in
        the form. Only these properties will have fields.
    :param exclude:
        An optional iterable with the property names that should be excluded
        from the form. All other properties will have fields.
    :param field_args:
        An optional dictionary of field names mapping to keyword arguments used
        to construct each field object.
    :param converter:
        A converter to generate the fields based on the model properties. If
        not set, ``ModelConverter`` is used.
    """
    field_dict = model_fields(model, only, exclude, field_args, converter)
    return type(model._meta.object_name + 'Form', (base_class, ), field_dict) 
开发者ID:snverse,项目名称:Sci-Finder,代码行数:29,代码来源:orm.py


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