def seed_db(): from models.Book import Book from models.User import User from main import bcrypt from faker import Faker import random faker = Faker() users = [] for i in range(5): user = User() user.email = f"test{i}@test.com" user.password = bcrypt.generate_password_hash("123456").decode("utf-8") db.session.add(user) users.append(user) db.session.commit() for i in range(20): book = Book() book.title = faker.catch_phrase() book.user_id = random.choice(users).id book.author = f"Super awesome author #{i}" db.session.add(book) db.session.commit() print("Tables seeded")
def seed_db(): from models.Book import Book from models.User import User from models.Page import Page from main import bcrypt from faker import Faker import random faker = Faker() users = [] for i in range(5): user = User() user.email = f"test{i}@test.com" user.password = bcrypt.generate_password_hash("123456").decode("utf-8") db.session.add(user) users.append(user) db.session.commit() for i in range(20): book = Book() book.title = faker.catch_phrase() book.user_id = random.choice(users).id book.author = faker.name() db.session.add(book) db.session.commit() for i in range(100): page = Page() page.page_content = faker.text(1500) page.page_number = random.randint(1, 300) page.book_id = random.randint(1, 20) db.session.add(page) db.session.commit() print("Tables seeded")