本文整理汇总了Python中models.Author.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Author.to_dict方法的具体用法?Python Author.to_dict怎么用?Python Author.to_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Author
的用法示例。
在下文中一共展示了Author.to_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import to_dict [as 别名]
def update_author(author_id):
"""Updates the author matching the id author_id.
Only the parameters to update or to add should be passed in the request body.
"""
author = Author.objects(id=author_id).get()
patched = Author(**dict(chain(author.to_dict().items(), request.get_json().items())))
patched.save()
return jsonify(patched.to_dict())
示例2: authors
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import to_dict [as 别名]
def authors():
"""Retrieves a list of authors from the database or create a new author.
When retrieving a list of authors, the URL can contain pagination parameters
page and per_page which default to 1 and 10 if omitted.
"""
if request.method == 'GET':
return paginate(resource_name='authors', endpoint='authors', objects=Author.objects)
author = Author(**request.get_json())
author.save()
return jsonify(author.to_dict()), 201