当前位置: 首页>>代码示例>>Python>>正文


Python Author.objects方法代码示例

本文整理汇总了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())
开发者ID:fendgroupproject,项目名称:backend,代码行数:11,代码来源:main.py

示例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())
开发者ID:fendgroupproject,项目名称:backend,代码行数:11,代码来源:main.py

示例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())
开发者ID:fendgroupproject,项目名称:backend,代码行数:13,代码来源:main.py

示例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
开发者ID:fendgroupproject,项目名称:backend,代码行数:23,代码来源:main.py

示例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())
开发者ID:fendgroupproject,项目名称:backend,代码行数:5,代码来源:main.py


注:本文中的models.Author.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。