Example #1
0
class User_Gift(db.Model):
    __tablename__ = 'user_gift'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    gift_id = db.Column(db.Integer, db.ForeignKey('merchant_gift.id'))
    booking_date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    expiry_date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('normal_user.normal_user_id'))
    status = db.Column(db.String(80))
Example #2
0
class Slot(db.Model):
    __tablename__ = 'slot'
    slot_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    startime = db.Column(db.Integer)
    endTime = db.Column(db.Integer)
    booking_date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    status = db.Column(db.String(80), nullable=False)
    qrCode = db.Column(db.String(80), nullable=True)
    current_count = db.Column(db.Integer, nullable=True)
    #merchant = db.relationship("Merchant", backref=db.backref("merchant", uselist=False))
    merchant_id = db.Column(db.Integer, db.ForeignKey('Merchant.merchant_id'))
    user_id = db.Column(db.Integer,
                        db.ForeignKey('normal_user.normal_user_id'))
Example #3
0
class ItemModel(db.Model):
    __tablename__ = "items"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)
    price = db.Column(db.Float(precision=2))

    store_id = db.Column(db.Integer, db.ForeignKey("stores.id"))
    store = db.relationship('StoreModel')

    def __init__(self, name, price, store_id):
        self.name = name
        self.price = price
        self.store_id = store_id

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

    def delete_db(self):
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def find_one_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    def json(self):
        return {"id": self.id, "name": self.name, "price": self.price}
Example #4
0
class Shop_Item(db.Model):
    __tablename__ = 'shop_item'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    merchant_id = db.Column(db.Integer, db.ForeignKey('Merchant.merchant_id'))
    #merchant = db.relationship("Merchant", backref=db.backref("merchant", uselist=False))
    item_value = db.Column(db.String(80), nullable=False)
    status = db.Column(db.String(80), nullable=False)
Example #5
0
class Merchant_Gift(db.Model):
    __tablename__ = 'merchant_gift'
    __table_args__ = {'extend_existing': True}
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    amount = db.Column(db.String(80), nullable=False)
    gift_name = db.Column(db.String(80), nullable=False)
    merchant_id = db.Column(db.Integer, db.ForeignKey('Merchant.merchant_id'))
    status = db.Column(db.String(80), nullable=False)
Example #6
0
class NormalUser(db.Model):
    __tablename__ = 'normal_user'
    normal_user_id = db.Column(db.Integer,
                               primary_key=True,
                               autoincrement=True)
    electricity_bill_number = db.Column(db.String(80), nullable=False)
    lat = db.Column(db.String(80))
    lng = db.Column(db.String(80))
    #geom = db.Column(Geometry(geometry_type='POINT', srid=4326))
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
Example #7
0
class Book(db.Model):
    __tablename__ = 'books'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(50))  # Book Title
    year = db.Column(db.Integer)
    author_id = db.Column(db.Integer,
                          db.ForeignKey('authors.id'),
                          nullable=False)

    def __init__(self, title, year, author_id=None):
        self.title = title
        self.year = year
        self.author_id = author_id

    def create(self):  # 向数据库中写入本对象数据
        db.session.add(self)
        db.session.commit()
        return self
Example #8
0
class Merchant(db.Model):
    __tablename__ = 'Merchant'
    merchant_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    shopName = db.Column(db.String(80), nullable=False)
    gstNumber = db.Column(db.String(80), nullable=False)
    shopCategory = db.Column(db.String(80), nullable=False)
    avgTime = db.Column(db.String(80), nullable=False)
    maxPeoplePerSlot = db.Column(db.String(80), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    lat = db.Column(db.String(80))
    lng = db.Column(db.String(80))
    #geom = db.Column(Geometry(geometry_type='POINT', srid=4326))

    @hybrid_method
    def distance(self, lat, lng):
        return gc_distance(lat, lng, float(self.lat), float(self.lng))

    @distance.expression
    def distance(cls, lat, lng):
        return gc_distance(lat,
                           lng,
                           cls.lat.cast(db.Float),
                           cls.lng.cast(db.Float),
                           math=func)
Example #9
0
class User_Roles(db.Model):
    __tablename__ = 'user_roles'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
    #user = db.relationship("Users", backref=db.backref("users", uselist=False))
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))