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


Python Activity.delete_many方法代码示例

本文整理汇总了Python中models.Activity.delete_many方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.delete_many方法的具体用法?Python Activity.delete_many怎么用?Python Activity.delete_many使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Activity的用法示例。


在下文中一共展示了Activity.delete_many方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete_record

# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import delete_many [as 别名]
def delete_record(record_model, id_number):
    """
    Delete a record from database

    :param record_model: The model for which to delete a record.
    :type record_model: :func:`sqlalchemy.ext.declarative.declarative_base`

    :param id_number: Recond id.
    :type id_number: Integer

    :returns: Success.
    :rtype: Boolean

    """
    try:
        instance = record_model.get_by_id(id_number)
        if isinstance(instance, Project):
            activities = Session.get('all', Activity.project_id == id_number)
            sessions = Session.get('all', Session.project_id == id_number)
            msg = 'Deleting sessions:'
            for session in sessions:
                msg = msg + '\r\n' + str(session) + (' PID {0}'.\
                                                     format(session.project_id)
                                                     )
            LOGGER.debug(msg)
            Activity.delete_many(activities)
            Session.delete_many(sessions)
        instance.delete()
        return True
    except SQLAlchemyError:
        log_msg = ('Delete record exception model {model_name!s} with '
                   'id {id_number}.')
        log_msg = log_msg.format(model_name=record_model.__name__,
                                 id_number=id_number)
        LOGGER.exception(log_msg)
        return False
开发者ID:diwa-aalto,项目名称:diwacs,代码行数:38,代码来源:common.py


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