-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (27 loc) · 1.2 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# import Flask and jsonify from flask
# import SQLAlchemy from flask_sqlalchemy
# initialize new flask app
# add configurations and database URI
# connect SQLAlchemy to the configured flask app
# uncomment models
# class User(db.Model):
# __tablename__ = 'users'
# id = db.Column(db.Integer, primary_key=True)
# username = db.Column(db.String(20), nullable=False)
# tweets = db.relationship('Tweet', backref='users', lazy=True)
# def to_dict(self):
# user = {'id': self.id, 'username': self.username, 'tweets': [tweet.to_dict() for tweet in self.tweets]}
# return user
#
# class Tweet(db.Model):
# __tablename__ = 'tweets'
# id = db.Column(db.Integer, primary_key=True)
# text = db.Column(db.Text, nullable=False)
# user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
# user = db.relationship('User', back_populates="tweets")
# def to_dict(self):
# tweet = {'id': self.id, 'text': self.text, 'user_id': self.user.id, 'user': self.user.username}
# return tweet
# define routes and their respective functions that return the correct data
# remember that each function must have a unique name
# run the server