コード例 #1
0
ファイル: bookings.py プロジェクト: shuman-shen/CarShare-IoT
class BookingModel(db.Model):
    """
    Bookings table schema and validation rules.

    :param int booking_id: primary key, auto-increment
    :param str car_number: foreign key, required.
    :param str username: foreign key, required.
    :param datetime departure_time: required.
    :param datetime return_time: required.
    """

    __tablename__ = 'Bookings'

    booking_id = db.Column(
        db.Integer, primary_key=True, autoincrement=True, nullable=False
    )
    car_number = db.Column(
        db.String(6), db.ForeignKey('Cars.car_number'), nullable=False
    )
    username = db.Column(
        db.String(100), db.ForeignKey('Users.username'), nullable=False
    )
    departure_time = db.Column(db.DateTime, nullable=False)
    return_time = db.Column(db.DateTime, nullable=False)
    created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    def save_to_db(self):
        """
        Save session to database.
        """
        db.session.add(self)
        db.session.commit()
コード例 #2
0
class UserModel(db.Model):
    """
    Users table schema and validation rules.

    :param str username: primary key, length: 3-15
    :param str password:  length: 8-30, required.
    :param str first_name:  length: 1-30, required.
    :param str last_name:  length: 1-30, required.
    :param str email:  max length: 1-30, required.
    """

    __tablename__ = 'Users'

    username = db.Column(db.String(100), primary_key=True, nullable=False)
    password = db.Column(db.String(260), nullable=False)
    first_name = db.Column(db.String(100), nullable=False)
    last_name = db.Column(db.String(100), nullable=False)
    email = db.Column(db.String(100), nullable=False)
    role = db.Column(db.String(20), nullable=False, default="user")
    bookings = db.relationship('BookingModel', backref='Users', lazy=True)

    def add_new_record(self):
        """
        Save session to database.
        """
        db.session.add(self)
        db.session.commit()
コード例 #3
0
ファイル: cars.py プロジェクト: shuman-shen/CarShare-IoT
class CarModel(db.Model):
    """
    Cars table schema and validation rules.

    :param str car_number: primary key, max length: 6
    :param str make: max length: 30, required.
    :param str body_type: max length: 30, required.
    :param int seats: range: 1-12, required.
    :param str colour: max length: 30, required.
    :param decimal cost_per_hour: non-negative, required.
    :param decimal latitude: range: -90 to 90, required.
    :param decimal longitude: range: -180 to 180, required.
    :param bool lock_status: required.
    """

    __tablename__ = 'Cars'

    car_number = db.Column(db.String(6), primary_key=True, nullable=False)
    make = db.Column(db.String(30), nullable=False)
    body_type = db.Column(db.String(30), nullable=False)
    colour = db.Column(db.String(30), nullable=False)
    seats = db.Column(db.Integer, nullable=False)
    # default: -37.804663448,144.957996168
    latitude = db.Column(db.Numeric(11, 9),
                         default=-37.804663448,
                         nullable=False)
    longitude = db.Column(db.Numeric(12, 9),
                          default=144.957996168,
                          nullable=False)
    cost_per_hour = db.Column(db.Numeric, nullable=False)

    # default: locked = True, unlock = False
    lock_status = db.Column(db.Boolean, nullable=False, default=True)
    bookings = db.relationship('BookingModel', backref='Cars', lazy=True)

    def save_to_db(self):
        """
        Save session to database.
        """
        db.session.add(self)
        db.session.commit()
コード例 #4
0
class Subjob(db.Model):
	id				= db.Column(db.Integer, primary_key=True)
	job_id		= db.Column(db.Integer)
	data			= db.Column(db.Text)
コード例 #5
0
class Job(db.Model):
	id				= db.Column(db.Integer, primary_key=True)
	status		= db.Column(db.Integer)
	expected	= db.Column(db.Integer, default=0)