本文整理匯總了Python中comments.models.Comment.depth方法的典型用法代碼示例。如果您正苦於以下問題:Python Comment.depth方法的具體用法?Python Comment.depth怎麽用?Python Comment.depth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類comments.models.Comment
的用法示例。
在下文中一共展示了Comment.depth方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: generate_comments
# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import depth [as 別名]
def generate_comments(n=NUMBER_OF_COMMENTS):
c = Comment(content=CONTENT[0])
c.save()
c.path = str(c.id)
c.save()
result = [c]
for i in xrange(1, n):
# choice - decides whether to add new comment with depth = 0 or reply to another comment
choice = randint(0, 1)
content_choice = randint(0, len(CONTENT) - 1)
lb = round(random(), 2)
# some of the comments should be hidden
c = Comment(_lower_bound=lb, visible=random() > 0.2, content=CONTENT[content_choice])
if choice == 0:
idx = randint(0, len(result) - 1)
c.depth = result[idx].depth + 1
c.parent = result[idx].id
c.save()
c.path = result[idx].path + ' ' + str(c.id)
c.save()
else:
c.depth = 0
c.save()
c.path = str(c.id)
c.save()
result.append(c)
示例2: test_generate_comments
# 需要導入模塊: from comments.models import Comment [as 別名]
# 或者: from comments.models.Comment import depth [as 別名]
def test_generate_comments(self):
c = Comment(depth=0, _lower_bound=0)
c.path = '0'
c.save()
result = [c]
for i in xrange(1, 1000):
ch = randint(0, 1)
lb = round(random(), 2)
c = Comment(_lower_bound=lb, visible=random() > 0.2)
if ch > 0.35:
idx = randint(0, len(result) - 1)
c.path = result[idx].path + ' ' + str(i)
c.depth = result[idx].depth + 1
c.parent = result[idx].id
c.save()
else:
c.depth = 0
c.path = str(i)
c.save()
result.append(c)