Example #1
0
class StoreModel(db.Model):
    __tablename__ = "stores"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80), unique=True)

    items = db.relationship("ItemModel", lazy='dynamic')

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

    def create_db(self):
        print(self.json())
        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,
            "items": [item.json() for item in self.items.all()]
        }
Example #2
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 #3
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 #4
0
class UserModel(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    password = db.Column(db.String(80))

    def __init__(self, username, password):
        self.username = username
        self.password = password

    @classmethod
    def find_user_by_name_and_password(cls, username, password):
        return cls.query.filter_by(username=username,
                                   password=password).first()

    @classmethod
    def find_user_by_id(cls, _id):
        return cls.query.filter_by(id=_id).first()

    @classmethod
    def find_user_by_username(cls, username):
        return cls.query.filter_by(username=username).first()

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

    def delete_user(self):
        db.session.delete(self)
        db.session.commit()
Example #5
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(80), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    password = db.Column(db.String(200), nullable=False)

    def __repr__(self):
        return '<User %r>' % self.username
Example #6
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 #7
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 #8
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 #9
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 #10
0
class Author(db.Model):

    __tablename__ = 'authors'

    id = db.Column(db.Integer , primary_key=True ,autoincrement=True)
    first_name = db.Column(db.String(20))
    last_name  = db.Column(db.String(20))
    created = db.Column( db.DateTime , server_default=db.func.now() )
    books = db.relationship('Book',backref='Author',cascade='all ,delete-orphan')

    def __init__(self, first_name, last_name, books=[]):
        self.first_name = first_name
        self.last_name = last_name
        self.books = books

    def create(self):
        db.session.add(self)
        db.session.commit()
        return self
Example #11
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 #12
0
class Users(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    phonenumber = db.Column(db.String(80), nullable=False)
    firstname = db.Column(db.String(80))
    lastname = db.Column(db.String(80))
    passwordhash = db.Column(db.String(80))
    references = db.Column(db.String(80))

    def __repr__(self):
        return "(%r, %r, %r, %r)" % (self.phonenumber, self.firstname,
                                     self.lastname, self.passwordhash)
Example #13
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 #14
0
class Resources(db.Model):

    TYPE_BANNER = 'banner'
    TYPE_NEWS = 'news'
    TYPE_MOVIE = 'movie'
    TYPE_PROJECT = 'project'
    TYPE_ABOUT = 'about'
    TYPE_WEBROLL = 'webroll'

    id = db.Column(db.BigInteger, primary_key=True)
    res_id = db.Column(db.String(32), index=True)
    res_tp = db.Column(db.String(16))
    content = db.Column(db.Text)
    created = db.Column(db.Integer)
    create_bb = db.Column(db.String(20))
    updated = db.Column(db.Integer)
    update_bb = db.Column(db.String(20))
    deleted = db.Column(db.Integer, default=0)

    def __init__(self):
        self.created = int(time.time())
        self.updated = self.created

    @staticmethod
    def create(res_tp, content, create_bb, res_id=None):
        r = Resources()
        r.res_tp = res_tp
        r.content = content
        r.create_bb = create_bb
        r.update_bb = create_bb

        r.res_id = res_id if res_id else '{0}_{1}'.format(r.res_tp, r.created)

        db.session.add(r)
        db.session.commit()

        return r

    def update(self):
        self.updated = int(time.time())
        db.session.commit()

    @staticmethod
    def bb_delete(res_tp, res_id, update_bb):
        now_ts = int(time.time())
        Resources.query.filter(Resources.res_id == res_id,
                               Resources.res_tp == res_tp).\
            update({'deleted': now_ts,
                    'updated': now_ts,
                    'update_bb': update_bb}, synchronize_session=False)

        db.session.commit()

    @staticmethod
    def update_up(res_tp, res_id, content, update_bb):
        now_ts = int(time.time())
        Resources.query.filter(Resources.res_id == res_id,
                               Resources.res_tp == res_tp).\
            update({'updated': now_ts,
                    'update_bb': update_bb,
                    'content': json.dumps(content)},
                   synchronize_session=False)

        db.session.commit()
Example #15
0
class Roles(db.Model):
    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    roleType = db.Column(db.String(80), nullable=False)
Example #16
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'))
Example #17
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(80), unique=True, nullable)