Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
flask-sqlalchemy
- Loading branch information
Showing
4 changed files
with
43 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from app import db | ||
from models import BlogPost | ||
|
||
# create the database and the db table | ||
db.create_all() | ||
|
||
# insert data | ||
db.session.add(BlogPost("Good", "I\'m good.")) | ||
db.session.add(BlogPost("Well", "I\'m well.")) | ||
db.session.add(BlogPost("Excellent", "I\'m excellent.")) | ||
db.session.add(BlogPost("Okay", "I\'m okay.")) | ||
|
||
# commit the changes | ||
db.session.commit() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from app import db | ||
|
||
|
||
class BlogPost(db.Model): | ||
|
||
__tablename__ = "posts" | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
title = db.Column(db.String, nullable=False) | ||
description = db.Column(db.String, nullable=False) | ||
|
||
def __init__(self, title, description): | ||
self.title = title | ||
self.description = description | ||
|
||
def __repr__(self): | ||
return '<title {}'.format(self.title) |
This file contains 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