models.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:aiohttp_json_api 作者: vovanbo 项目源码 文件源码
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)
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号