def populate(comments: Sequence['Comment'], authors: Sequence['People'],
count=100) -> Generator['Article', None, None]:
import mimesis
aid = mimesis.Numbers()
article = mimesis.Text()
answers = list(comments)
def get_random_answers(max):
counter = 0
while answers and counter < max:
yield answers.pop(random.randint(0, len(answers) - 1))
counter += 1
return (
Article(
id=aid.between(1, count),
title=article.title(),
author=random.choice(authors),
comments=[c for c in get_random_answers(random.randint(1, 10))]
)
for _ in range(count)
)
评论列表
文章目录