def post_create(): post_name = request.form.get("post_name") post_description = request.form.get("post_description") profile = Profiles.query.filter_by(user_id=current_user.id).first() new_post = Post() new_post.post_name = post_name new_post.post_description = post_description new_post.profile_id = current_user.id # new_post.profile_id = profile.profileid #profile.post.append(new_post) db.session.add(new_post) db.session.commit() # return jsonify(post_schema.dump(new_post)) return redirect(url_for('post.post_index'))
def seed_db(): from models.Profiles import Profiles from faker import Faker from models.Users import Users from main import bcrypt from models.Post import Post import random faker = Faker() profiles = [] true_or_false = [True, False] posts = [] for i in range(10): user = Users() user.email = f"test{i}@test.com" user.password = bcrypt.generate_password_hash("123456").decode("utf-8") db.session.add(user) #accounts.append(user) db.session.commit() for i in range(10): profile = Profiles() profile.username = faker.name() profile.fname = faker.first_name() profile.lname = faker.last_name() profile.account_active = faker.boolean() profile.user_id = i + 1 db.session.add(profile) profiles.append(profile) db.session.commit() for i in range(30): new_post = Post() new_post.post_name = faker.name() new_post.post_description = faker.catch_phrase() new_post.profile_id = random.choice(profiles).profileid posts.append(new_post) db.session.add(new_post) db.session.commit() print("Tables seeded")
def seed_db(): from models.Profiles import Profiles from faker import Faker from models.Users import Users from main import bcrypt from models.Post import Post from models.Messages import Messages import random faker = Faker() profiles = [] true_or_false = [True, False] posts = [] for i in range(10): user = Users() user.email = f"test{i}@test.com" user.password = bcrypt.generate_password_hash("123456").decode("utf-8") db.session.add(user) #accounts.append(user) db.session.commit() for i in range(10): profile = Profiles() profile.username = faker.name() profile.fname = faker.first_name() profile.lname = faker.last_name() profile.account_active = faker.boolean() profile.user_id = i + 1 profile.github = faker.name() profile.front_end = random.choice(true_or_false) profile.back_end = random.choice(true_or_false) profile.full_stack = random.choice(true_or_false) db.session.add(profile) profiles.append(profile) db.session.commit() for i in range(30): new_post = Post() new_post.post_name = faker.name() new_post.post_description = faker.catch_phrase() new_post.account_active = random.choice(true_or_false) new_post.front_end = random.choice(true_or_false) new_post.back_end = random.choice(true_or_false) new_post.full_stack = random.choice(true_or_false) new_post.completed = random.choice(true_or_false) new_post.post_github = faker.url() new_post.profile_id = random.choice(profiles).profileid posts.append(new_post) db.session.add(new_post) db.session.commit() for i in range(50): new_message = Messages() new_message.post_id = random.choice(posts).postid new_message.profile_id = random.choice(profiles).profileid new_message.messages = faker.catch_phrase() new_message.timestamp = faker.date_between(start_date="-1y", end_date="+1y") db.session.add(new_message) db.session.commit() print("Tables seeded")