我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用app.db.Model()。
def __init__(self, **kwargs): super(Model, self).__init__(**kwargs) # do custom initialization here
def paginate(query, page, per_page=20, error_out=True): """ ????????db.session.query??????????db.Model???????? ??db.session.query????????paginate??? ???????? """ if error_out and page < 1: abort(404) items = query.limit(per_page).offset((page - 1) * per_page).all() if not items and page != 1 and error_out: abort(404) if page == 1 and len(items) < per_page: total = len(items) else: total = query.order_by(None).count() return Pagination(query, page, per_page, total, items)
def make_shell_context(): reflec_maps = {} from app import models for obj_name in models.__dict__: obj = getattr(models, obj_name) if hasattr(obj, '__bases__') and obj.__bases__[0] is db.Model: reflec_maps[obj_name] = obj reflec_maps['app'] = app reflec_maps['db'] = db return reflec_maps