本文整理汇总了Python中myapp.models.User方法的典型用法代码示例。如果您正苦于以下问题:Python models.User方法的具体用法?Python models.User怎么用?Python models.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类myapp.models
的用法示例。
在下文中一共展示了models.User方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: model_form
# 需要导入模块: from myapp import models [as 别名]
# 或者: from myapp.models import User [as 别名]
def model_form(model, db_session=None, base_class=Form, only=None,
exclude=None, field_args=None, converter=None, exclude_pk=True,
exclude_fk=True, type_name=None):
"""
Create a wtforms Form for a given SQLAlchemy model class::
from wtforms.ext.sqlalchemy.orm import model_form
from myapp.models import User
UserForm = model_form(User)
:param model:
A SQLAlchemy mapped model class.
:param db_session:
An optional SQLAlchemy Session.
: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.
:param exclude_pk:
An optional boolean to force primary key exclusion.
:param exclude_fk:
An optional boolean to force foreign keys exclusion.
:param type_name:
An optional string to set returned type name.
"""
if not hasattr(model, '_sa_class_manager'):
raise TypeError('model must be a sqlalchemy mapped model')
type_name = type_name or str(model.__name__ + 'Form')
field_dict = model_fields(
model, db_session, only, exclude, field_args, converter,
exclude_pk=exclude_pk, exclude_fk=exclude_fk
)
return type(type_name, (base_class, ), field_dict)
示例2: model_form
# 需要导入模块: from myapp import models [as 别名]
# 或者: from myapp.models import User [as 别名]
def model_form(model, db_session=None, base_class=Form, only=None,
exclude=None, field_args=None, converter=None, exclude_pk=True,
exclude_fk=True, type_name=None):
"""
Create a wtforms Form for a given SQLAlchemy model class::
from wtalchemy.orm import model_form
from myapp.models import User
UserForm = model_form(User)
:param model:
A SQLAlchemy mapped model class.
:param db_session:
An optional SQLAlchemy Session.
: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.
:param exclude_pk:
An optional boolean to force primary key exclusion.
:param exclude_fk:
An optional boolean to force foreign keys exclusion.
:param type_name:
An optional string to set returned type name.
"""
if not hasattr(model, '_sa_class_manager'):
raise TypeError('model must be a sqlalchemy mapped model')
if not exclude:
exclude = []
model_mapper = model.__mapper__
for prop in model_mapper.iterate_properties:
if not hasattr(prop, 'direction') and prop.columns[0].primary_key:
if exclude_pk:
exclude.append(prop.key)
if hasattr(prop, 'direction') and exclude_fk and \
prop.direction.name != 'MANYTOMANY':
for pair in prop.local_remote_pairs:
exclude.append(pair[0].key)
type_name = type_name or str(model.__name__ + 'Form')
field_dict = model_fields(model, db_session, only, exclude, field_args, converter)
return type(type_name, (base_class, ), field_dict)
示例3: model_form
# 需要导入模块: from myapp import models [as 别名]
# 或者: from myapp.models import User [as 别名]
def model_form(model, db_session=None, base_class=Form, only=None,
exclude=None, field_args=None, converter=None, exclude_pk=True,
exclude_fk=True, type_name=None):
"""
Create a wtforms Form for a given SQLAlchemy model class::
from wtalchemy.orm import model_form
from myapp.models import User
UserForm = model_form(User)
:param model:
A SQLAlchemy mapped model class.
:param db_session:
An optional SQLAlchemy Session.
: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.
:param exclude_pk:
An optional boolean to force primary key exclusion.
:param exclude_fk:
An optional boolean to force foreign keys exclusion.
:param type_name:
An optional string to set returned type name.
"""
if not hasattr(model, '_sa_class_manager'):
raise TypeError('model must be a sqlalchemy mapped model')
type_name = type_name or str(model.__name__ + 'Form')
field_dict = model_fields(
model, db_session, only, exclude, field_args, converter,
exclude_pk=exclude_pk, exclude_fk=exclude_fk
)
return type(type_name, (base_class, ), field_dict)