Skip to content

Commit d5b6df3

Browse files
committed
Added models
1 parent 98ce769 commit d5b6df3

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed

app.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
db_uri = 'mysql+pymysql://root:password@localhost/feedreader'
5+
app.config['SQLALCHEMY_DATABASE_URI'] = db_uri

db.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from app import app
2+
from flask_sqlalchemy import SQLAlchemy
3+
db = SQLAlchemy(app)

models/__init__.py

Whitespace-only changes.

models/article.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from db import db
2+
import datetime
3+
4+
class Article(db.Model):
5+
id = db.Column(db.Integer, primary_key=True)
6+
title = db.Column(db.Text, nullable=False)
7+
body = db.Column(db.Text, nullable=False)
8+
link = db.Column(db.Text, nullable=False)
9+
guid = db.Column(db.String(255), nullable=False)
10+
unread = db.Column(db.Boolean, default=True, nullable=False)
11+
source_id = db.Column(db.Integer, db.ForeignKey('source.id'), nullable=False)
12+
source = db.relationship('Source', db.backref('articles', lazy=True))
13+
date_added = db.Column(db.DateTime, default=datetime.datetime.utcnow)
14+
date_published = db.Column(db.DateTime)
15+
__table_args__ = (
16+
db.UniqueConstraint('source_id', 'guid', name='uc_source_guid'),
17+
)

models/source.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from db import db
2+
import datetime
3+
4+
class Source(db.Model):
5+
id = db.Column(db.Integer, primary_key=True)
6+
title = db.Column(db.Text, nullable=False)
7+
subtitle = db.Column(db.Text, nullable=False)
8+
link = db.Column(db.Text, nullable=False)
9+
feed = db.Column(db.Text, nullable=False)
10+
date_added = db.Column(db.DateTime, default=datetime.datetime.utcnow)

run.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from app import app
2+
from db import db
3+
from models import article, source
4+
5+
with app.app_context():
6+
db.create_all()
7+
8+
app.run()

0 commit comments

Comments
 (0)