本文整理汇总了Python中model.Article.select方法的典型用法代码示例。如果您正苦于以下问题:Python Article.select方法的具体用法?Python Article.select怎么用?Python Article.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Article
的用法示例。
在下文中一共展示了Article.select方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_articles
# 需要导入模块: from model import Article [as 别名]
# 或者: from model.Article import select [as 别名]
def get_articles():
'''
Get list of articles for particular user.
TODO: Needs paging.
'''
username = request.headers.get('x-koala-username')
apikey = request.headers.get('x-koala-key')
user = locate_user(username, apikey)
userarticles = Article.select().join(User).where((User.id==user.id)).dicts()
return jsonify({'articles': list(userarticles)})
示例2: get_article
# 需要导入模块: from model import Article [as 别名]
# 或者: from model.Article import select [as 别名]
def get_article(id):
'''
Get specific article based on its ID.
'''
username = request.headers.get('x-koala-username')
apikey = request.headers.get('x-koala-key')
user = locate_user(username, apikey)
article = Article.select().join(User).where((Article.id==id) & (User.id == user.id)).dicts()
if article.count() != 1:
abort(404)
return jsonify({'article': article[0]})
示例3: update_article
# 需要导入模块: from model import Article [as 别名]
# 或者: from model.Article import select [as 别名]
def update_article(id):
username = request.headers.get('x-koala-username')
apikey = request.headers.get('x-koala-key')
user = locate_user(username, apikey)
reqjson = request.get_json()
article = Article.select().join(User).where((Article.id==id) & (User.id == user.id)).get()
if not article:
abort(404)
elif not reqjson:
abort(400)
else:
if reqjson.has_key('read'):
article.read = reqjson['read'] != False
if reqjson.has_key('favorite'):
article.favorite = reqjson['favorite'] != False
article.save()
return '', 204