class BoardDto(db.Model): __tablename__ = 'boards' __table_args__ = {'mysql_collate': 'utf8_general_ci'} id: int = db.Column(db.Integer, primary_key=True, index=True) email: str = db.Column(db.String(100), db.ForeignKey(MemberDto.email), nullable=False) article_type: str = db.Column(db.String(50), nullable=False) title: str = db.Column(db.String(50), nullable=False) content: str = db.Column(db.String(20000), nullable=False) regdate: datetime = db.Column(db.String(1000), default=datetime.datetime.now()) member = db.relationship('MemberDto', back_populates='boards') comments = db.relationship('CommentDto', back_populates='board', lazy='dynamic') def __init__(self, email, article_type, title, content, regdate): self.email = email self.article_type = article_type self.title = title self.content = content self.regdate = regdate def __repr__(self): return 'Board(id={}, email={}, article_type={}, title={}, content={}, regdate={})'.format( self.id, self.email, self.article_type, self.title, self.content, self.regdate) @property def json(self): return { 'id': self.id, 'email': self.email, 'article_type': self.article_type, 'title': self.title, 'content': self.content, 'regdate': self.regdate } def save(self): db.session.add(self) db.commit() def delete(self): db.session.delete(self) db.commit()
class CommentDto(db.Model): __tablename__ = "comments" __table_args__ = {"mysql_collate": "utf8_general_ci"} id: int = db.Column(db.Integer, primary_key=True, index=True) board_id: int = db.Column(db.Integer, db.ForeignKey(BoardDto.id), nullable=False) email: str = db.Column(db.String(100), db.ForeignKey(MemberDto.email), nullable=False) comment: str = db.Column(db.String(500), nullable=False) regdate: datetime = db.Column(db.String(1000), default=datetime.datetime.now(), nullable=False) comment_ref: int = db.Column(db.Integer, nullable=False) comment_level: int = db.Column(db.Integer, nullable=False) comment_step: int = db.Column(db.Integer, nullable=False) board = db.relationship('BoardDto', back_populates='comments') member = db.relationship('MemberDto', back_populates='comments') def __init__(self, board_id, email, comment, regdate, comment_ref, comment_level, comment_step): self.board_id = board_id self.email = email self.comment = comment self.regdate = regdate self.comment_ref = comment_ref self.comment_level = comment_level self.comment_step = comment_step def __repr__(self): return f'id={self.id}, board_id={self.board_id}, email={self.email}, comment={self.comment}, regdate={self.regdate}, ref={self.comment_ref}, level={self.comment_level}, step={self.comment_step}' @property def json(self): return { 'id': self.id, 'board_id': self.board_id, 'email': self.email, 'comment': self.comment, 'regdate': self.regdate, 'comment_ref': self.comment_ref, 'comment_level': self.comment_level, 'comment_step': self.comment_step }
class TradingDto(db.Model): __tablename__ = "tradings" __table_args__ = {'mysql_collate': 'utf8_general_ci'} id: int = db.Column(db.Integer, primary_key=True, index=True) email: str = db.Column(db.String(100), db.ForeignKey(MemberDto.email), nullable=False) stock_type: str = db.Column(db.String(20), nullable=False) stock_ticker: str = db.Column(db.String(50), nullable=False) stock_qty: int = db.Column(db.Integer, nullable=False) price: float = db.Column(db.FLOAT, nullable=False) trading_date: str = db.Column(db.String(50), default=datetime.datetime.now()) member = db.relationship('MemberDto', back_populates='tradings') def __init__(self, email, stock_type, stock_ticker, stock_qty, price, trading_date): self.email = email self.stock_type = stock_type self.stock_ticker = stock_ticker self.stock_qty = stock_qty self.price = price self.trading_date = trading_date def __repr__(self): return 'Trading(trading_id={}, email={}, stock_type={}, stock_ticker={}, stock_qty={}, price={}, trading_date={})'.format( self.id, self.email, self.stock_type, self.stock_ticker, self.stock_qty, self.price, self.trading_date) @property def json(self): return { 'id': self.id, 'email': self.email, 'stock_type': self.stock_type, 'stock_ticker': self.stock_ticker, 'stock_qty': self.stock_qty, 'price': self.price, 'trading_date': self.trading_date }
class MemberDto(db.Model): __tablename__ = "members" __table_args__ = {"mysql_collate": "utf8_general_ci"} email: str = db.Column(db.String(100), primary_key=True, index=True) password: str = db.Column(db.String(50), nullable=False) name: str = db.Column(db.String(50), nullable=False) profile: str = db.Column(db.String(200), default='noimage.png') geography: str = db.Column(db.String(50)) gender: str = db.Column(db.String(10)) age: int = db.Column(db.Integer) tenure: int = db.Column(db.Integer, default=0) stock_qty: int = db.Column(db.Integer, default=0) balance: float = db.Column(db.FLOAT, default=0.0) has_credit: int = db.Column(db.Integer) credit_score: int = db.Column(db.Integer) is_active_member: int = db.Column(db.Integer, nullable=False, default=1) estimated_salary: float = db.Column(db.FLOAT) role: str = db.Column(db.String(30), nullable=False, default='ROLE_USER') probability_churn: float = db.Column(db.FLOAT, default=-1) exited: int = db.Column(db.Integer, nullable=False, default=0) tradings = db.relationship('TradingDto', back_populates='member', lazy='dynamic') boards = db.relationship('BoardDto', back_populates='member', lazy='dynamic') comments = db.relationship('CommentDto', back_populates='member', lazy='dynamic') def __init__(self, email, password, name, profile, geography, gender, age, tenure, stock_qty, balance, has_credit, credit_score, is_active_member, estimated_salary, role, probability_churn, exited): self.email = email self.password = password self.name = name self.profile = profile self.geography = geography self.gender = gender self.age = age self.tenure = tenure self.stock_qty = stock_qty self.balance = balance self.has_credit = has_credit self.credit_score = credit_score self.is_active_member = is_active_member self.estimated_salary = estimated_salary self.role = role self.probability_churn = probability_churn self.exited = exited def __repr__(self): return 'Member(email={}, password={},'\ 'name={}, profile={}, geography={}, gender={}, age={}, tenure={}, stock_qty={}, balance={},'\ 'hasCrCard={}, credit_score={}, isActiveMember={}, estimatedSalary={}, role={}, probability_churn={}, exited={}'\ .format(self.email, self.password, self.name, self.profile, self.geography, self.gender, self.age, self.tenure, self.stock_qty, self.balance, self.has_credit, self.credit_score, self.is_active_member, self.estimated_salary, self.role, self.probability_churn, self.exited) @property def json(self): return { 'email': self.email, 'password': self.password, 'name': self.name, 'profile': self.profile, 'geography': self.geography, 'gender': self.gender, 'age': self.age, 'tenure': self.tenure, 'stock_qty': self.stock_qty, 'balance': self.balance, 'has_credit': self.has_credit, 'credit_score': self.credit_score, 'is_active_member': self.is_active_member, 'estimated_salary': self.estimated_salary, 'role': self.role, 'probability_churn': self.probability_churn, 'exited': self.exited }