本文整理汇总了Python中app.models.Category.parent方法的典型用法代码示例。如果您正苦于以下问题:Python Category.parent方法的具体用法?Python Category.parent怎么用?Python Category.parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Category
的用法示例。
在下文中一共展示了Category.parent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_06_rename_category
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import parent [as 别名]
def test_06_rename_category(self):
"""测试分类改名"""
cate1 = Category(name='cate1')
db.session.add(cate1)
db.session.commit()
cate2 = Category(name='cate2')
cate2.parent = cate1
db.session.add(cate2)
db.session.commit()
cate3 = Category(name='cate3')
cate3.parent = cate2
db.session.add(cate3)
db.session.commit()
p = Post()
Post.publish(post=p,
title='post',
content='post',
category=cate2)
cate1.name = 'cate11'
cate2.name = 'cate222'
self.assertTrue(cate2 in cate1.children.all() and
cate2.link == 'cate11/cate222' and
cate3 in cate2.children.all() and
cate3.link == 'cate11/cate222/cate3' and
cate3.level == 2 and
cate3.parent == cate2 and
cate2.posts_count == 1 and
cate1.posts_count == 1 and
cate3.posts_count == 0)
示例2: test_07_order_cate
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import parent [as 别名]
def test_07_order_cate(self):
"""测试分类顺序"""
cate1 = Category(name='cate1')
db.session.add(cate1)
db.session.commit()
cate2 = Category(name='cate2',
order=1)
cate3 = Category(name='cate3',
order=2)
cate3.parent = cate1
cate2.parent = cate1
db.session.add(cate2)
db.session.add(cate3)
db.session.commit()
self.assertTrue(cate2.order < cate3.order)
示例3: test_05_category_family
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import parent [as 别名]
def test_05_category_family(self):
"""测试分类层级关系"""
cate1 = Category(name='cate1')
db.session.add(cate1)
db.session.commit()
cate2 = Category(name='cate2')
cate2.parent = cate1
db.session.add(cate2)
db.session.commit()
cate3 = Category(name='cate3')
cate3.parent = cate2
db.session.add(cate3)
db.session.commit()
self.assertTrue(cate2 in cate1.children.all() and
cate2.link == 'cate1/cate2' and
cate3 in cate2.children.all() and
cate3.link == 'cate1/cate2/cate3' and
cate1.parent is None)
示例4: setUp
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import parent [as 别名]
def setUp(self):
self.app = create_app('test')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
cate1 = Category(name='cate1')
db.session.add(cate1)
db.session.commit()
cate2 = Category(name='cate2')
cate2.parent = cate1
db.session.add(cate2)
db.session.commit()
cate3 = Category(name='cate3')
cate3.parent = cate2
db.session.add(cate3)
db.session.commit()
tag1 = Tag(name='tag1')
tag2 = Tag(name='tag2')
tag3 = Tag(name='tag3')
db.session.add_all([tag1, tag2, tag3])
db.session.commit()