def topics(count=50): fake = Faker() user_count = User.query.count() board_count = Board.query.count() for i in range(count): u = User.query.offset(randint(0, user_count - 1)).first() b = Board.query.offset(randint(0, board_count - 1)).first() p = Topic.new(views=randint(0, 1000), title=fake.text(10), content=fake.text(), board_id=b.id, user_id=u.id) Topic.session.add(p) Topic.session.commit()
def add(): form = request.form.to_dict() u = current_user() form['user_id'] = u.id Topic.new(**form) return redirect(url_for('.index'))