Example #1
0
from app import db, User, Post
db.create_all()
john = User(username='******')
post = Post()
post.title = "Hello World"
post.body = "This is the first post of jhon"
post.author = john
db.session.add(post)
db.session.add(john)
jim = User(username='******')
db.session.add(jim)
post2 = Post()
post2.title = "Woooow"
post2.body = "I'm the maaaaask"
post2.author = jim
db.session.add(post2)

db.session.commit()
print(User.query.all())
print(Post.query.all())
Example #2
0
from app import db, User, Post

db.create_all()  # create tables from models

user1 = User(name="Sadhan Sarker", email='*****@*****.**')

post1 = Post()
post1.title = "Blog Post Title 1"
post1.body = "This is the first blog post 1"
post1.author = user1

db.session.add(post1)
db.session.add(user1)
db.session.commit()

print(User.query.all())
print(Post.query.all())