class Tour(db.Model, TimestampMixin, IDMixin): __tablename__ = 'tours' is_active = db.Column(db.Boolean, default=True) name = db.Column(db.VARCHAR(255), nullable=False) description = db.Column(db.VARCHAR(5000), nullable=False) city_or_province = db.Column(db.VARCHAR(255), nullable=False) common_address = db.Column(db.VARCHAR(255), nullable=False) duration = db.Column(db.Integer, nullable=False) min_size = db.Column(db.Integer, nullable=False) max_size = db.Column(db.Integer, nullable=False) price_per_participant = db.Column(db.Integer, nullable=False) transportations = db.Column(db.VARCHAR(255), nullable=False) images = db.Column(db.VARCHAR(500), nullable=False) organizer_name = db.Column(db.VARCHAR(255), nullable=False) organizer_email = db.Column(db.VARCHAR(255), nullable=False) organizer_phone_number = db.Column(db.VARCHAR(255), nullable=False) organizer_avatar = db.Column(db.VARCHAR(255), nullable=False) tour_payment_informations = db.relationship('TourPaymentInformation', back_populates='tour') tour_bookings = db.relationship('TourBooking', back_populates='tour') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class Hotel(db.Model, TimestampMixin, IDMixin): __tablename__ = 'hotels' is_active = db.Column(db.Boolean, default=True) name = db.Column(db.VARCHAR(255), nullable=False) description = db.Column(db.VARCHAR(255), nullable=False) city_or_province = db.Column(db.VARCHAR(255), nullable=False) address = db.Column(db.VARCHAR(255), nullable=False) phone_number = db.Column(db.VARCHAR(255), nullable=False) email = db.Column(db.VARCHAR(255), nullable=False) room_types = db.Column(db.VARCHAR(255), nullable=False) utilities = db.Column(db.VARCHAR(255), nullable=False) checkin = db.Column(db.TIME(), nullable=False) checkout = db.Column(db.TIME(), nullable=False) image = db.Column(db.VARCHAR(255), nullable=False) longitude = db.Column(db.FLOAT, nullable=False) latitude = db.Column(db.FLOAT, nullable=False) price_standard = db.Column(db.INTEGER, nullable=True) available_room_standard = db.Column(db.INTEGER, nullable=True) tax_standard = db.Column(db.FLOAT, nullable=True) image_standard = db.Column(db.VARCHAR(255), nullable=True) price_deluxe = db.Column(db.INTEGER, nullable=True) available_room_deluxe = db.Column(db.INTEGER, nullable=True) tax_deluxe = db.Column(db.FLOAT, nullable=True) image_deluxe = db.Column(db.VARCHAR(255), nullable=True) payment_informations = db.relationship('PaymentInformation', back_populates='hotel') hotel_bookings = db.relationship('HotelBooking', back_populates='hotel') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class Role(db.Model, TimestampMixin, IDMixin): __tablename__ = 'roles' is_active = db.Column(db.Boolean, default=True) name = db.Column(db.VARCHAR(255), nullable=False) code = db.Column(db.VARCHAR(20), nullable=False) has_all_permissions = db.Column(db.Boolean, default=False) users = db.relationship('User', back_populates='role') permissions = db.relationship('Permission', secondary='role_permissions') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class TourBooking(db.Model, TimestampMixin, IDMixin): __tablename__ = 'tour_bookings' status = db.Column(db.Enum(BookingStatus), nullable=False) start_date = db.Column(db.DATE(), nullable=False) user_id = db.Column(db.VARCHAR(255), nullable=False) guests = db.Column(db.INTEGER, nullable=True) price_per_participant = db.Column(db.INTEGER, nullable=False) guest_name = db.Column(db.VARCHAR(255), nullable=False) guest_phone_number = db.Column(db.VARCHAR(255), nullable=False) guest_email = db.Column(db.VARCHAR(255), nullable=False) note = db.Column(db.VARCHAR(255), nullable=True) image_witness = db.Column(db.VARCHAR(255), nullable=True) grand_total = db.Column(db.INTEGER, nullable=False) tour_id = db.Column( db.Integer, db.ForeignKey('tours.id', name='FK_tours__booking__id', ondelete='RESTRICT', onupdate='CASCADE')) tour = db.relationship('Tour', back_populates='tour_bookings') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class HotelBooking(db.Model, TimestampMixin, IDMixin): __tablename__ = 'hotel_bookings' status = db.Column(db.Enum(BookingStatus), nullable=False) checkin_date = db.Column(db.DATE(), nullable=False) checkout_date = db.Column(db.DATE(), nullable=False) room_type = db.Column(db.VARCHAR(255), nullable=False) note = db.Column(db.VARCHAR(255), nullable=True) user_id = db.Column(db.VARCHAR(255), nullable=False) rooms = db.Column(db.INTEGER, nullable=True) guests = db.Column(db.INTEGER, nullable=True) room_price = db.Column(db.INTEGER, nullable=False) room_tax = db.Column(db.FLOAT, nullable=False) guest_name = db.Column(db.VARCHAR(255), nullable=False) guest_phone_number = db.Column(db.VARCHAR(255), nullable=False) guest_email = db.Column(db.VARCHAR(255), nullable=True) bank_code = db.Column(db.Enum(Bank), nullable=True) paided = db.Column(db.INTEGER, nullable=True) image_witness = db.Column(db.VARCHAR(255), nullable=True) grand_total = db.Column(db.INTEGER, nullable=False) hotel_id = db.Column( db.Integer, db.ForeignKey('hotels.id', name='FK_hotels__booking__id', ondelete='RESTRICT', onupdate='CASCADE')) hotel = db.relationship('Hotel', back_populates='hotel_bookings') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class User(db.Model, TimestampMixin, IDMixin): __tablename__ = 'users' is_active = db.Column(db.Boolean, default=True) username = db.Column(db.VARCHAR(255), nullable=False) email = db.Column(db.VARCHAR(255), nullable=False) password_hash = db.Column(db.VARCHAR(255), nullable=False) role_id = db.Column( db.Integer, db.ForeignKey('roles.id', name='FK_roles__id', ondelete='SET NULL', onupdate='CASCADE'), ) role = db.relationship('Role', back_populates='users') @property def password(self): raise AttributeError('password: write-only field') @password.setter def password(self, password): self.password_hash = bcrypt.generate_password_hash(password).decode( 'utf-8') def check_password(self, password): return bcrypt.check_password_hash(self.password_hash, password) def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}
class PaymentInformation(db.Model, TimestampMixin, IDMixin): __tablename__ = 'payment_informations' bank_code = db.Column(db.Enum(Bank), nullable=False) account_number = db.Column(db.VARCHAR(255), nullable=False) account_name = db.Column(db.VARCHAR(255), nullable=False) hotel_id = db.Column( db.Integer, db.ForeignKey('hotels.id', name='FK_hotels__id', ondelete='RESTRICT', onupdate='CASCADE')) hotel = db.relationship('Hotel', back_populates='payment_informations') def to_dict(self): return {c.name: getattr(self, c.name) for c in self.__table__.columns}