class Reply(db.Model): __tablename__ = 'replys' id = db.Column(db.Integer, primary_key=True) comment = db.Column(db.String(300), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) tweet_id = db.Column(db.Integer, db.ForeignKey('tweets.id'), nullable=False) user = db.relationship('User', uselist=False, backref="replys")
class Likes(db.Model): __tablename__ = 'likes' id = db.Column(db.Integer, primary_key=True) color = db.Column(db.String(50), nullable=True) tweet_id = db.Column(db.Integer, db.ForeignKey('tweets.id'), nullable=False) tweet = db.relationship("Tweet", backref="good") user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
class Followers(db.Model): __tablename__ = 'followers' id = db.Column(db.Integer, primary_key=True) source_user_id = db.Column(db.Integer, db.ForeignKey('login.id'), nullable=False) target_user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
class Profile(db.Model): __tablename__ = 'profiles' id = db.Column(db.Integer, primary_key=True) avatar = db.Column(db.String(900), nullable=True) bio = db.Column(db.String(500), nullable=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) user = db.relationship('User', backref="profiles")
class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255), nullable=False) address = db.Column(db.String(255), nullable=False) number = db.Column(db.String(20), nullable=False) login_id = db.Column(db.Integer, db.ForeignKey('login.id'), nullable=False) profile = db.relationship('Profile', uselist=False, backref="users") tweets = db.relationship('Tweet', backref="users") follow = db.relationship('Followers', backref="users")
class Tweet(db.Model): __tablename__ = 'tweets' id = db.Column(db.Integer, primary_key=True) word = db.Column(db.String(300), nullable=True) photo = db.Column(db.String(900), nullable=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) user = db.relationship('User', backref=db.backref("users", lazy=True)) #add reply = db.relationship('Reply', backref="tweet") # replyを1つだけ表示のため #add good_count = db.Column(db.Integer, default=0) good = False Good = db.relationship("Likes", backref="tweets")