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


Python User.count方法代码示例

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


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

示例1: test_delete

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
 def test_delete(self):
     self.create_data(4, table=1)
     assert User.at(1).delete().execute() == 1
     assert User.where(
         (User.name == 'name1') | (User.name == 'name2')
     ).delete().execute() == 1
     assert User.count() == 2
开发者ID:zhangjinglei,项目名称:skylark,代码行数:9,代码来源:tests.py

示例2: test_delete

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
 def test_delete(self):
     if db_type != 'sqlite':  # sqlite dosen't support 'delete xx from xxx'
         assert self.models.where(
             User.id == Post.user_id).delete().execute() == 8
         assert self.models.where(
             User.id == Post.user_id).select().execute().count == 0
         assert Post.count() == 0
         assert User.count() == 0
开发者ID:bopo,项目名称:skylark,代码行数:10,代码来源:tests.py

示例3: test_count

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
 def test_count(self):
     self.create_data(4)
     assert User.count() == 4
     assert Post.count() == 4
     query = User.select(fn.count(User.id))
     result = query.execute()
     assert result.count == 1
     assert result.tuples()[0][0] == 4
开发者ID:bopo,项目名称:skylark,代码行数:10,代码来源:tests.py

示例4: test_count

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
 def test_count(self):
     self.create_data(4)
     assert User.count() == 4
     query = (Post & User).select(
         fn.count(User.id).alias('count_user_id'),
         fn.count(Post.post_id).alias('count_post_id'))
     results = query.execute()
     assert results.count == 1
     func = results.one()
     assert func.count_user_id == 4
     assert func.count_post_id == 4
开发者ID:zhangjinglei,项目名称:skylark,代码行数:13,代码来源:tests.py

示例5: test_transaction

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
    def test_transaction(self):
        database.set_autocommit(False)
        with database.transaction() as t:
            User.create(name='jack', email='[email protected]')

        with database.transaction() as t:
            try:
                User.create(name='amy', id=1)
            except:
                t.rollback()
        database.set_autocommit(True)
        assert User.count() == 1
开发者ID:bopo,项目名称:skylark,代码行数:14,代码来源:tests.py

示例6: test_create

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
    def test_create(self):
        user = User.create(name='jack', email='[email protected]')
        assert user.data == {
            'name': 'jack', 'email': '[email protected]', 'id': 1
        }
        assert user in User
        assert user._in_db
        assert User.count() == 1

        _user = User.getone()
        assert _user.data == user.data
        assert _user._in_db
开发者ID:bopo,项目名称:skylark,代码行数:14,代码来源:tests.py

示例7: test_update

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
    def test_update(self):
        user = User.create(name='jack', email='[email protected]')
        assert user.id == 1
        assert user.name == 'jack'
        assert user.email == '[email protected]'
        assert User.count() == 1

        query = User.at(1).update(email='[email protected]')
        rows_affected = query.execute()
        assert rows_affected == 1
        user = User.getone()
        assert user.id == 1 and user.email == '[email protected]'
开发者ID:bopo,项目名称:skylark,代码行数:14,代码来源:tests.py

示例8: delete

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
    def delete(self,id):
        if not current_user.is_admin() and current_user.id != id:
            abort(401)
        if User.count() <= 1:
            abort(403)

        user = User.get_by_id(id)
        try:
            if user is None:
                raise Exception(gettext('User not found'))
            name  = user.name
            User.delete(user.id)
            flash(gettext('The user "%(name)s" was removed', name=name))
        except:
            flash(gettext('Error while removing the user'), 'error')

        if request.method == 'POST':
            return redirect(url_for('UsersView:index'))               
        return jsonify(redirect_to=url_for('UsersView:index'))
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:21,代码来源:views.py

示例9: test_inst_save

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
    def test_inst_save(self):
        user = User(name='jack', email='[email protected]')
        assert user.save() == 1  # insert
        assert user._in_db and user in User
        assert User.count() == 1
        assert User.getone().name == 'jack'
        user.email = '[email protected]'
        assert user.save() == 1  # update
        assert User.getone().email == '[email protected]'
        # test inst._cache
        assert user.save() == 0  # nothing change

        user = User(name='jack', email='[email protected]')
        user.set_in_db(True)
        try:
            user.save()
        except PrimaryKeyValueNotFound:
            pass
        else:
            raise Exception
开发者ID:bopo,项目名称:skylark,代码行数:22,代码来源:tests.py

示例10: test_model_inst_save

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
    def test_model_inst_save(self):
        user = User(name='jack', email='[email protected]')
        assert user.save() == 1
        assert User.count() == 1
        assert User.getone().name == 'jack'
        user.name = 'amy'
        assert user.save() == 1
        assert User.findone(id=1).name == 'amy'

        user = User(name='test!', email='[email protected]')
        id = user.save()
        assert id == 2
        assert User.at(2).getone().name == 'test!'
        user.name = 'run a test!'
        rows_affected = user.save()
        assert rows_affected == 1
        query = User.at(2).select(User.name)
        results = query.execute()
        user = results.one()
        try:
            user.name = 'hello'
            user.save()
        except PrimaryKeyValueNotFound:
            pass
开发者ID:zhangjinglei,项目名称:skylark,代码行数:26,代码来源:tests.py

示例11:

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
from models import User

count = User.count()
max_id = User.max(User.id)
min_id = User.min(User.id)
sum_of_ids = User.sum(User.id)
avg_of_ids = User.avg(User.id)
开发者ID:YechengZhou,项目名称:skylark,代码行数:9,代码来源:aggregators.py

示例12: test_insert

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import count [as 别名]
 def test_insert(self):
     query = User.insert(name='jack', email='[email protected]')
     assert query.execute() == 1
     assert User.count() == 1
     user = User.getone()
     assert user.name == 'jack' and user.email == '[email protected]'
开发者ID:bopo,项目名称:skylark,代码行数:8,代码来源:tests.py


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