Ejemplo n.º 1
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    display_name = db.Column(db.String(15), nullable=False)
    image = db.Column(db.String(255))
    name = db.Column(db.String(50), nullable=False)
    name_ruby = db.Column(db.String(50), nullable=False)
    birthday = db.Column(db.Date)
    payment = db.Column(db.String(255))
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
    auth = db.relationship('Auth', backref='user')
    item = db.relationship('Item', backref='user')

    def __init__(self,
                 display_name,
                 image='',
                 name='',
                 name_ruby='',
                 birthday='',
                 payment=''):
        self.display_name = display_name
        self.image = image
        self.name = name
        self.name_ruby = name_ruby
        self.birthday = birthday
        self.payment = payment

    def setAttr(self,
                display_name,
                image='',
                name='',
                name_ruby='',
                birthday='',
                payment=''):
        self.display_name = display_name
        self.image = image
        self.name = name
        self.name_ruby = name_ruby
        self.birthday = birthday
        self.payment = payment

    def postRecord(self):
        db.session.add(self)
        db.session.commit()
        return self

    @classmethod
    def getUserInfo(cls, user_id):
        record = cls.query.filter_by(id=user_id).first()
        return record
Ejemplo n.º 2
0
class Candlestick(db.Model):
    __tablename__ = 'candlesticks'
    __table_args__ = (db.UniqueConstraint(
        'datetime', 'asset_id', name='unique_candlesticks_date_asset_id'), )

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    datetime = db.Column(db.DateTime, nullable=False)
    low_price = db.Column(db.Float, nullable=True, default=None)
    high_price = db.Column(db.Float, nullable=True, default=None)
    open_price = db.Column(db.Float, nullable=True, default=None)
    close_price = db.Column(db.Float, nullable=True, default=None)
    volume = db.Column(db.Float, nullable=True)
    weighted_volume = db.Column(db.Float, nullable=True)
    asset_id = db.Column(db.Integer, db.ForeignKey('assets.id'))

    asset = db.relationship('Asset',
                            back_populates='candlesticks',
                            uselist=False)

    def __repr__(self) -> str:
        return (
            f'Candlestick(datetime={self.datetime}, close_price={self.close_price}, open_price={self.open_price}, '
            f'low_price={self.low_price}, high_price={self.high_price}), volume={self.volume}'
        )

    __str__ = __repr__
Ejemplo n.º 3
0
class Item(db.Model):
    __tablename__ = 'item'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(20), nullable=False)  # 商品名
    description = db.Column(db.Text)  # 商品説明文
    period = db.Column(db.Integer, nullable=False)  # 販売日数
    remaining_days = db.Column(db.Integer, nullable=False)
    remaining_format_id = db.Column(
        db.Integer,
        db.ForeignKey('remaining_format.id',
                      onupdate='CASCADE',
                      ondelete='CASCADE'))
    category_id = db.Column(db.Integer,
                            db.ForeignKey('category.id',
                                          onupdate='CASCADE',
                                          ondelete='CASCADE'))  # 設定したカテゴリのID
    shipment = db.Column(db.Integer, nullable=False)  # 配送にかかる時間(日)
    price = db.Column(db.Integer, nullable=False)  # 商品の値段
    state = db.Column(db.Integer)  # 商品の状態
    user_id = db.Column(
        db.Integer,
        db.ForeignKey('user.id', onupdate='CASCADE', ondelete='CASCADE'))
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
    item_image = db.relationship('ItemImage', backref='item')

    def __init__(self,
                 name=None,
                 description=None,
                 period=None,
                 remaining_days=None,
                 remaining_format_id=None,
                 category_id=None,
                 shipment=None,
                 price=None,
                 state=None,
                 user_id=None):
        self.name = name
        self.description = description
        self.period = period
        self.remaining_days = remaining_days
        self.remaining_format_id = remaining_format_id
        self.category_id = category_id
        self.shipment = shipment
        self.price = price
        self.state = state
        self.user_id = user_id

    def postRecord(self):
        db.session.add(self)
        db.session.commit()

    @classmethod
    def getProductById(cls, item_id):
        record = cls.query.filter_by(id=item_id).first()
        return record
Ejemplo n.º 4
0
class Asset(db.Model):
    __tablename__ = 'assets'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    ticker = db.Column(db.String, nullable=True, default=True)
    isin = db.Column(db.String, nullable=True, default=True)
    currency = db.Column(db.String, nullable=True, default='USD')

    candlesticks = db.relationship('Candlestick', back_populates='asset')

    def __repr__(self) -> str:
        return f'Asset(isin={self.isin}, currency={self.currency}, ticker={self.ticker})'

    __str__ = __repr__
Ejemplo n.º 5
0
class Page(db.Model):

    __tablename__ = "pages" # table name will default to name of the model

    # Create columns
    id = db.Column(db.Integer, primary_key=True)
    # page name
    name = db.Column(db.String(length=120))
    # Creation time for page.
    created = db.Column(db.DateTime, default=datetime.utcnow)
    # set relationship
    pages = db.relationship('LanguageDetail', backref='pages', lazy=True)

    # this is not essential, but a valuable method to overwrite as this is what we will see when we print out an instance in a REPL.
    def __repr__(self):
        return "<Page(id='%s', name='%s', created='%s')>" % (
                      self.id, self.name, self.created)
Ejemplo n.º 6
0
class RemainingFormat(db.Model):
    __tablename__ = 'remaining_format'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
    item = db.relationship('Item', backref='remaining_format')

    def __init__(self, name=''):
        self.name = name

    def setAttr(self, name=''):
        self.name = name

    def postRecord(self):
        db.session.add(self)
        db.session.commit()
        return self

    @classmethod
    def getRecord(cls, category_id):
        record = cls.query.filter_by(id=category_id).first()
        return record

    @classmethod
    def addTestData(cls):
        models = []
        data_lists = ['whole', 'day', 'week', 'month']
        for data in data_lists:
            models.append(cls(data))

        db.session.add_all(models)
        db.session.commit()
Ejemplo n.º 7
0
class Category(db.Model):
    __tablename__ = 'category'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.now)
    updated_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.now,
                           onupdate=datetime.now)
    item = db.relationship('Item', backref='category')

    def __init__(self, name=''):
        self.name = name

    def setAttr(self, name=''):
        self.name = name

    def postRecord(self):
        db.session.add(self)
        db.session.commit()
        return self

    @classmethod
    def getCategory(cls, category_id):
        record = cls.query.filter_by(id=category_id).first()
        return record

    @classmethod
    def addTestData(cls):
        categories = []
        data_lists = ['grain', 'vegetable', 'fruit', 'other']
        for data in data_lists:
            categories.append(cls(data))

        db.session.add_all(categories)
        db.session.commit()