本文整理匯總了Python中models.board.Board.get_board_by_text_id方法的典型用法代碼示例。如果您正苦於以下問題:Python Board.get_board_by_text_id方法的具體用法?Python Board.get_board_by_text_id怎麽用?Python Board.get_board_by_text_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.board.Board
的用法示例。
在下文中一共展示了Board.get_board_by_text_id方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get
# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import get_board_by_text_id [as 別名]
def get(self, text_id):
try:
board = Board.get_board_by_text_id(text_id)
except NoResultFound:
return abort(404)
#last_post = Post.query.order_by(Post.id.desc()).limit(1).subquery()
#last_post_alias = aliased(Post, last_post)
# threads = db.session.query(Thread, last_post_alias).filter_by(board_id=board.id).join(last_post_alias, Thread.id == last_post_alias.thread_id).order_by(Thread.id.desc()).all()
threads = db.session.query(Thread).filter_by(board_id=board.id).order_by(Thread.id.desc()).all()
#threads = db.session.query(Thread, Post)\
# .filter_by(board_id=board.id)\
# .order_by(Thread.id.desc())\
# .join(Post, Thread.id == Post.thread_id)\
# .all()
#print(db.session.query(Thread, Post)
# .filter_by(board_id=board.id)
# .order_by(Thread.id.desc())
# .join(Post, Thread.id == Post.thread_id).statement)
#for thread in threads:
# print(thread.__dict__)
return render_template("forum_threads_view.jinja2", board=board, title=board.name, can_post=True,
threads=threads)
示例2: get
# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import get_board_by_text_id [as 別名]
def get(self, board_text_id):
try:
board = Board.get_board_by_text_id(board_text_id)
except NoResultFound:
return abort(404)
form = ThreadPostForm()
return render_template("forum_thread_post.jinja2", board=board, form=form)
示例3: post
# 需要導入模塊: from models.board import Board [as 別名]
# 或者: from models.board.Board import get_board_by_text_id [as 別名]
def post(self, board_text_id):
try:
board = Board.get_board_by_text_id(board_text_id)
except NoResultFound:
return abort(404)
form = ThreadPostForm()
if form.validate():
thread = Thread(form.title.data, board.id, current_user.id)
db.session.add(thread)
db.session.commit()
post = Post(form.content.data, thread, current_user.id)
post.op = True
db.session.add(post)
db.session.commit()
return render_template("forum_thread_post.jinja2", board=board, form=form)