本文整理汇总了Python中app.models.Category.name方法的典型用法代码示例。如果您正苦于以下问题:Python Category.name方法的具体用法?Python Category.name怎么用?Python Category.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.Category
的用法示例。
在下文中一共展示了Category.name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_06_rename_category
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import name [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: handle
# 需要导入模块: from app.models import Category [as 别名]
# 或者: from app.models.Category import name [as 别名]
def handle(self, *args, **options):
archivo = args[0]
f = open(archivo, 'r')
l = f.readlines()
count = 0
for c in l:
c = c[1:]
c = c[:-2]
slug = c.replace(' ', '-')
slug = slug.replace(',', '')
slug = slug.decode('latin-1')
slug = unicodedata.normalize('NFKD', slug).encode('ASCII', 'ignore')
slug = slug.lower()
category = Category()
category.name = c
category.slug = slug
category.order = 0
category.active = True
try:
category.save()
count += 1
self.stdout.write('Categoria %s almacenada' % c)
except Exception:
self.stdout.write('Categoria %s NO almacenada' % c)
self.stdout.write('Se almacenaron %d categorias' % count)