Esempio n. 1
0
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)
Esempio n. 2
0
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
        }
Esempio n. 3
0
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
        }