From 4f585448d7bc10fa4f0358c35d5bc3595c9bce8c Mon Sep 17 00:00:00 2001 From: Xevion Date: Sun, 27 Mar 2022 10:20:53 -0500 Subject: [PATCH] Extend fake shell command for adding fake posts into DB --- create_app.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/create_app.py b/create_app.py index ec0d08d..f138842 100644 --- a/create_app.py +++ b/create_app.py @@ -1,3 +1,4 @@ +import random from datetime import datetime import click @@ -67,8 +68,9 @@ def create_app(): @click.argument("count") def create_fake_users(count: int): fake = Faker() + count = int(count) users = {} - for _ in range(int(count)): + for _ in range(count): profile: dict = fake.simple_profile() users[profile['username']] = profile @@ -82,6 +84,15 @@ def create_app(): print(f'Committing {len(users)} users into DB.') db.session.commit() + post_count: int = 0 + for author in random.choices(User.query.all(), k=count // 4): + new_post = Post(author=author.id, text=fake.paragraph(nb_sentences=2)) + db.session.add(new_post) + post_count += 1 + + print(f'Committing {post_count} posts into the DB.') + db.session.commit() + @app.cli.command("create_all") def db_create_all() -> None: db.create_all(app=app)