本文整理汇总了Python中models.Author.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Author.objects方法的具体用法?Python Author.objects怎么用?Python Author.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Author
的用法示例。
在下文中一共展示了Author.objects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_project
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import objects [as 别名]
def delete_project(project_id):
"""Deletes the project matching the id project_id."""
project = Project.objects(id=project_id).get()
project.delete()
# Removes the project from the list of the author projects.
Author.objects(id=project.author_id).update_one(pull__projects=project.id)
return jsonify(project.to_dict())
示例2: update_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import objects [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())
示例3: delete_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import objects [as 别名]
def delete_author(author_id):
"""Deletes the author matching the id author_id."""
author = Author.objects(id=author_id).get()
# Deletes all the projects of this author.
for project_id in author.projects:
delete_project(project_id)
author.delete()
return jsonify(author.to_dict())
示例4: projects
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import objects [as 别名]
def projects():
"""Retrieves a list of projects from the database or create a new project.
When retrieving a list of projects, the URL can contain pagination parameters
page and per_page which default respectively to 1 and 10 if omitted.
"""
if request.method == 'GET':
return paginate(resource_name='projects', endpoint='projects', objects=Project.objects)
json = request.get_json()
author_id = json.get('author_id')
if author_id is not None:
assert_author_exists(json.get('author_id'))
project = Project(**json)
project.save()
# Add the project in the list of the author projects.
Author.objects(id=project.author_id).update_one(push__projects=project.id)
return jsonify(project.to_dict()), 201
示例5: get_author
# 需要导入模块: from models import Author [as 别名]
# 或者: from models.Author import objects [as 别名]
def get_author(author_id):
"""Retrieves the author matching the id author_id."""
return jsonify(Author.objects(id=author_id).get().to_dict())