コード例 #1
0
ファイル: models.py プロジェクト: chinchy/car-service
class Service(db.Model):

    __tablename__ = 'services'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    cost_our = db.Column(db.Numeric(18, 2))
    cost_foreign = db.Column(db.Numeric(18, 2))
コード例 #2
0
class Equipment(db.Model):
    """设备信息"""
    __tablename__ = 'equipment'

    # 表的结构
    ID = db.Column(db.Integer, primary_key=True, unique=True, nullable=False)
    EQP_ID = db.Column(db.String(45), nullable=False)
    Location = db.Column(db.String(45))
    Longitude = db.Column(db.Numeric(10, 6))
    Latitude = db.Column(db.Numeric(10, 6))
    Type = db.Column(db.String(45))
    IP = db.Column(db.String(45))
    Status = db.Column(db.Integer, nullable=False, default=1)
    CreateTime = db.Column(db.DateTime, nullable=False, default=datetime.now)
    ModifyTime = db.Column(db.DateTime)
コード例 #3
0
class Coupon(db.Model, Base):
    """Model for Udemy course coupon db table."""

    __tablename__ = "coupons"

    id = db.Column(db.Integer, primary_key=True)
    courseId = db.Column(db.Integer, db.ForeignKey("courses.id"))
    code = db.Column(db.String, nullable=False)
    link = db.Column(db.String, nullable=False)
    price = db.Column(db.Numeric(4, 2), nullable=False)
    utcExpirationISO = db.Column(db.DateTime(timezone=True), nullable=False)

    def __init__(
        self,
        code: str,
        link: str,
        utcExpirationISO: str,
        price: float,
        courseId: int = None,
        update_db: bool = True,
    ):
        """Create record and add to db, translating the expiration date to utc."""

        self.courseId = courseId
        self.code = code
        self.utcExpirationISO = dateutil.parser.parse(utcExpirationISO)
        self.price = price
        self.link = link

        if update_db:
            self.update_db()

    def to_dict(self):
        """Return the called upon resource to dictionary format."""
        return {
            "id": self.id,
            "courseId": self.courseId,
            "code": self.code,
            "link": self.link,
            "price": float(self.price),
            "utcExpirationISO": datetime.isoformat(self.utcExpirationISO),
        }

    def is_valid(self) -> bool:
        """Return boolean representing whether the coupon is valid."""

        return self.utcExpirationISO > datetime.now(utc)

    def update(self, updated_data):
        """Update with new data."""

        for key, value in updated_data.items():
            if key == "id":
                continue
            setattr(self, key, value)

    def __repr__(self):
        """Return a pretty print version of the retrieved resource."""
        return f""" < CourseCoupon(id={self.id},
コード例 #4
0
ファイル: models.py プロジェクト: Mc01/forex-grabber
class Ticker(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    currency_code = db.Column(db.String(length=CURRENCY_ISO_LENGTH),
                              nullable=False,
                              index=True)
    currency_rate = db.Column(db.Numeric(precision=DECIMAL_PRECISION,
                                         scale=DECIMAL_EXPONENT),
                              nullable=False)
    amount_requested = db.Column(db.Numeric(precision=DECIMAL_PRECISION,
                                            scale=DECIMAL_EXPONENT),
                                 nullable=False)
    final_amount = db.Column(db.Numeric(precision=DECIMAL_PRECISION,
                                        scale=DECIMAL_EXPONENT),
                             nullable=False)
    created_at = db.Column(db.DateTime,
                           nullable=False,
                           default=datetime.utcnow)

    def __repr__(self):
        return f"({self.id}) <Ticker for {self.currency_code}: {self.final_amount}>"
コード例 #5
0
ファイル: coupon_model.py プロジェクト: bonnie/bonniedotdev
class Coupon(db.Model, Base):
    """Model for Udemy course coupon db table."""

    __tablename__ = "coupons"

    id = db.Column(db.Integer, primary_key=True)
    courseId = db.Column(db.Integer, db.ForeignKey("courses.id"))
    link = db.Column(db.String, nullable=False)
    price = db.Column(db.Numeric(4, 2), nullable=False)
    utcExpirationISO = db.Column(db.DateTime(timezone=True), nullable=False)

    def __init__(
        self,
        link: str,
        utcExpirationISO: str,
        price: float,
        courseId: int = None,
        update_db: bool = True,
    ):
        """Create record and add to db, translating the expiration date to utc."""

        self.courseId = courseId
        self.utcExpirationISO = dateutil.parser.parse(utcExpirationISO)
        self.price = price
        self.link = link

        if update_db:
            self.update_db()

    def to_dict(self):
        """Return the called upon resource to dictionary format."""
        return {
            "id": self.id,
            "courseId": self.courseId,
            "link": self.link,
            "price": float(self.price),
            "utcExpirationISO": datetime.isoformat(self.utcExpirationISO),
        }

    def is_valid(self) -> bool:
        """Return boolean representing whether the coupon is valid."""

        return self.utcExpirationISO > datetime.now(utc)

    def update_from_patch(self, json_patch: Dict):
        """Update based on JsonPatch."""

        current_data = self.to_dict()

        # Apply patch to existing dict
        updated_data = jsonpatch.apply_patch(current_data, json_patch)

        # Apply the patched dictionary back to the model
        for key, value in updated_data.items():
            setattr(self, key, value)

        self.update_db()

    def __repr__(self):
        """Return a pretty print version of the retrieved resource."""
        return f""" < CourseCoupon(id={self.id},
コード例 #6
0
class Payment(db.Model):
    id = db.Column(db.Numeric(4, 0), primary_key=True)
    invoice_number = db.Column(db.Numeric, db.ForeignKey('invoice.number'))
    payment_date = db.Column(db.DateTime, default=datetime.now())
    payment_amount = db.Column(db.Integer, nullable=False)
コード例 #7
0
class Invoice(db.Model):
    number = db.Column(db.Numeric(4, 0), primary_key=True)
    order_id = db.Column(db.String, db.ForeignKey('order.id'))
    invoice_status_code = db.Column(db.String, db.ForeignKey(RefInvoiceStatusCode.invoice_status_code))
    invoice_date = db.Column(db.DateTime, default=datetime.now())
    invoice_details = db.Column(db.String)