class Login(db.Model): __tablename__ = 'login' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255), nullable=False) password = db.Column(db.String(50), nullable=False) users = db.relationship("User", uselist=False, backref="login")
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) email = db.Column(db.String(255), nullable=False) name = db.Column(db.String(255), nullable=False) username = db.Column(db.String(255), nullable=False) password = db.Column(db.String(50), nullable=False) login_id = db.Column(db.Integer, db.ForeignKey('login.id'), nullable=False)
class Post(db.Model): __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(255), nullable=False) photopost = db.Column(db.String(200), nullable=False) tagpost = db.Column(db.String(200), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=func.now()) updated_at = db.Column(db.DateTime, nullable=False, default=func.now(), onupdate=func.now()) login_id = db.Column(db.Integer, db.ForeignKey('login.id'), nullable=False)
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('Follow', 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("Good",backref="tweets")
class Good(db.Model): __tablename__ = 'good' 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 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")