class ItemDto(db.Model): __tablename__='items' __table_args__={'mysql_collate':'utf8_general_ci'} id : int = db.Column(db.Integer, primary_key=True, index=True) name : str = db.Column(db.String(30)) price : str = db.Column(db.String(30)) articles = db.relationship('ArticleDto', lazy='dynamic') def __init__(self, id, name, price): self.id = id self.name = name self.price = price def __repr__(self): return f'Item(id={self.id}, name={self.name}, price={self.price})' @property def json(self): return {'id': self.id, 'name': self.name, 'price': self.price} def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class ArticleDto(db.Model): __tablename__ = "articles" __table_args__={'mysql_collate':'utf8_general_ci'} art_id: int = db.Column(db.Integer, primary_key=True, index=True) title: str = db.Column(db.String(100)) content: str = db.Column(db.String(500)) user_id: str = db.Column(db.String(30), db.ForeignKey(UserDto.user_id)) item_id: int = db.Column(db.Integer, db.ForeignKey(ItemDto.item_id)) def __init__(self, title, content, user_id, item_id): self.title = title self.content = content self.user_id = user_id self.item_id = item_id def __repr__(self): return f'art_id={self.art_id}, user_id={self.user_id}, item_id={self.item_id},\ title={self.title}, content={self.content}' @property def json(self): return { 'art_id': self.art_id, 'user_id': self.user_id, 'item_id' : self.item_id, 'title' : self.title, 'content' : self.content }
class ReviewDto(db.Model): __tablename__ = "reviews" __table_args__ = {'mysql_collate': 'utf8_general_ci'} rvw_id: int = db.Column(db.Integer, primary_key=True, index=True) title: str = db.Column(db.String(100)) content: str = db.Column(db.String(500)) user_id = db.Column(db.String(10), db.ForeignKey(UserDto.user_id)) user = db.relationship('UserDto', back_populates='articles') item_id = db.Column(db.Integer, db.ForeignKey(ItemDto.item_id)) item = db.relationship('ItemDto', back_populates='articles') def __init__(self, title, content, user_id, item_id): self.title = title self.content = content self.user_id = user_id self.item_id = item_id def __repr__(self): return f'rvw_id={self.rvw_id}, user_id={self.user_id}, item_id={self.item_id},\ title={self.title}, content={self.content}' def json(self): return { 'rvw_id': self.rvw_id, 'user_id': self.user_id, 'item_id': self.item_id, 'title': self.title, 'content': self.content }
class UserDto(db.Model): __tablename__ = 'users' __table_args__ = {'mysql_collate': 'utf8_general_ci'} user_id: str = db.Column(db.String(10), primary_key=True, index=True) password: str = db.Column(db.String(1)) name: str = db.Column(db.String(100)) pclass: int = db.Column(db.Integer) gender: int = db.Column(db.Integer) age_group: int = db.Column(db.Integer) embarked: int = db.Column(db.Integer) rank: int = db.Column(db.Integer) # orders = db.relationship('OrderDto', back_populates='user', lazy='dynamic') # prices = db.relationship('PriceDto', back_populates='user', lazy='dynamic') articles = db.relationship('ArticleDto', back_populates='user', lazy='dynamic') def __init__(self, user_id, password, name, pclass, gender, age_group, embarked, rank): self.user_id = user_id self.password = password self.name = name self.pclass = pclass self.gender = gender self.age_group = age_group self.embarked = embarked self.rank = rank def __repr__(self): return f'User(user_id={self.user_id},\ password={self.password},name={self.name}, pclass={self.pclass}, gender={self.gender}, \ age_group={self.age_group}, embarked={self.embarked}, rank={self.rank})' def __str__(self): return f'User(user_id={self.user_id},\ password={self.password},name={self.name}, pclass={self.pclass}, gender={self.gender}, \ age_group={self.age_group}, embarked={self.embarked}, rank={self.rank})' def json(self): return { 'userId': self.user_id, 'password': self.password, 'name': self.name, 'pclass': self.pclass, 'gender': self.gender, 'ageGroup': self.age_group, 'embarked': self.embarked, 'rank': self.rank }
class ItemDto(db.Model): __tablename__='items' __table_args__={'mysql_collate':'utf8_general_ci'} item_id : int = db.Column(db.Integer, primary_key=True, index=True) item_name : str = db.Column(db.String(30)) default_price = db.Column(db.Integer, nullable=True) #orders = db.relationship('OrderDto', back_populates='item', lazy='dynamic') #prices = db.relationship('PriceDto', back_populates='item', lazy='dynamic') articles = db.relationship('ReviewDto', back_populates='item', lazy='dynamic') def __init__(self, item_name, default_price): self.item_name = item_name self.default_price = default_price def __repr__(self): return f'Item(item_id={self.item_id}, item_name={self.item_name},\ default_price={self.default_price})' @property def json(self): return {'itemId': self.item_id, 'item_name': self.item_name, 'default_price': self.default_price} def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class OrderDto(db.Model): __tablename__ = 'orders' order_id = db.Column(db.Integer, primary_key=True) order_quantity = db.Column(db.Integer) order_price = db.Column(db.Integer) order_delivery = db.Column(db.Date) order_placed = db.Column(db.Date) user_id = db.Column(db.String(10), db.ForeignKey(UserDto.user_id)) user = db.relationship('UserDto', back_populates='orders') item_id = db.Column(db.Integer, db.ForeignKey(ItemDto.item_id)) item = db.relationship('ItemDto', back_populates='orders') def __init__(self, user_id, item_id, order_price, order_quantity, order_delivery, order_placed): self.user_id = user_id self.item_id = item_id self.order_quantity = order_quantity self.order_price = order_price self.order_delivery = order_delivery self.order_placed = order_placed def __repr__(self): return '<Order {0}>'.format(self.orderDelivery)
class UserDto(db.Model): __tablename__ = 'users' __table_args__ = {'mysql_collate': 'utf8_general_ci'} userid: str = db.Column(db.String(10), primary_key=True, index=True) password: str = db.Column(db.String(1)) name: str = db.Column(db.String(100)) pclass: int = db.Column(db.Integer) gender: int = db.Column(db.Integer) age_group: int = db.Column(db.Integer) embarked: int = db.Column(db.Integer) rank: int = db.Column(db.Integer) def __init__(self, userid, password, name, pclass, gender, age_group, embarked, rank): self.userid = userid self.password = password self.name = name self.pclass = pclass self.gender = gender self.age_group = age_group self.embarked = embarked self.rank = rank def __repr__(self): return f'User(id={self.id},userid={self.userid},\ password={self.password},name={self.name}, pclass={self.pclass}, gender={self.gender}, \ age_group={self.age_group}, embarked={self.embarked}, rank={self.rank})' @property def json(self): return { 'userid': self.userid, 'password': self.password, 'name': self.name, 'pclass': self.pclass, 'gender': self.gender, 'age_group': self.age_group, 'embarked': self.embarked, 'rank': self.rank }
class NewsDto(db.Model): __tablename__ = 'naver_news' __table_args__ = {'mysql_collate':'utf8_general_ci'} news_id : int = db.Column(db.String(30), primary_key = True, index=True) # date : datetime = db.Column(db.datetime) sentiment_analysis :str = db.Column(db.String(30)) keywords :str = db.Column(db.String(30)) def __init__(self, news_id, date, sentiment_analysis, keywords): self.news_id = news_id self.date = date self.sentiment_analysis = sentiment_analysis self.keywords = keywords def __repr__(self): return f'news_id={self.news_id}, date={self.date}, sentiment_analysis={self.sentiment_analysis},\ keywords={self.keywords}' @property def json(self): return { 'news_id': self.news_id, 'date': self.date, 'sentiment_analysis' : self.sentiment_analysis, 'keywords' : self.keywords } def save(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()
class CabbageDto(db.Model): __tablename__ = 'cabbages' __table_args__ = {'mysql_collate': 'utf8_general_ci'} year: str = db.Column(db.String(10), primary_key=True, index=True) avg_temp: float = db.Column(db.Float) min_temp: float = db.Column(db.Float) max_temp: float = db.Column(db.Float) rain_fall: float = db.Column(db.Float) avg_price: int = db.Column(db.Integer) def __init__(self, year, avg_temp, min_temp, max_temp, rain_fall, avg_price): self.year = year self.avg_temp = avg_temp self.min_temp = min_temp self.max_temp = max_temp self.rain_fall = rain_fall self.avg_price = avg_price def __repr__(self): return f'Cabbage(year= {self.year}, avg_temp={self.avg_temp}, min_temp={self.min_temp}\