Created
February 11, 2019 05:24
-
-
Save waltzfordebby/138ebb24bc5a645813632885578421ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 4. | |
| pipenv install flask-sqlalchemy | |
| python | |
| from flaskblog import db | |
| db.create_all() | |
| from flaskblog import User, Post | |
| user_1 = User(username='Corey', email='C@demo.com', password='password') | |
| db.session.add(user_1) | |
| user_2 = User(username='JohnDoe', email='jd@demo.com', password='password') | |
| db.session.add(user_2) | |
| db.session.commit() | |
| User.query.all() | |
| User.query.first() | |
| User.query.filter_by(username='Corey').all() | |
| User.query.filter_by(username='Corey').first() | |
| user = User.query.filter_by(username='Corey').first() | |
| user | |
| user.id | |
| user = User.query.get(1) | |
| user | |
| user.posts | |
| user.id | |
| post_1 = Post(title='Blog 1', content='First Post Content!', user_id=user.id) | |
| post_2 = Post(title='Blog 2', content='Second Post Content', user_id=user.id) | |
| db.session.add(post_1) | |
| db.session.add(post_2) | |
| db.session.commit() | |
| user.posts | |
| for post in user.posts | |
| print(post.title) | |
| post = Post.query.first() | |
| post | |
| post.user_id | |
| post.author | |
| db.drop_all() | |
| db.create_all() | |
| User.query.all() | |
| Post.query.all() | |
| 5. | |
| from flaskblog import db | |
| from flaskblog.models import User, Post | |
| db.create_all() | |
| User.query.all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment