class User(db.Model): id = db.Column(db.String(32), primary_key=True) user_profile = db.relationship('UserProfile', backref='user', uselist=False, lazy=True) likes = db.relationship('Like', backref='user', lazy=True) comments = db.relationship('Comment', backref='user', lazy=True) bookings = db.relationship('Booking', backref='user', lazy=True) email = db.Column(db.String(255), nullable=False, unique=True) role = db.Column(db.Integer, nullable=False) hash_password = db.Column(db.String(255), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) deleted_at = db.Column(db.DateTime) def __init__(self, _id, email, hash_password, role=1): self.id = _id self.email = email self.hash_password = hash_password self.role = role @classmethod def find_by_email(cls, email): return cls.query.filter_by(email=email).first() @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first() @classmethod def get_all_users(cls): return User.query.all() def delete(self): db.session.delete(self) db.session.commit() def save_to_db(self): db.session.add(self) db.session.commit()
class Member(db.Model): id = db.Column(db.String(32), primary_key=True) accommodations = db.relationship('Accommodation', backref='member', lazy=True) promotions = db.relationship('Promotion', backref='member', lazy=True) images = db.relationship('Image', backref='member', lazy=True) bookings = db.relationship('Booking', backref='member', lazy=True) email = db.Column(db.String(255), nullable=False, unique=True) hash_password = db.Column(db.String(255), nullable=False) role = db.Column(db.SmallInteger, nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) deleted_at = db.Column(db.DateTime) def __init__(self, _id, email, hash_password, role): self.id = _id self.email = email self.hash_password = hash_password self.role = role @classmethod def find_by_email(cls, email): return cls.query.filter_by(email=email).first() @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first() @classmethod def get_all_member(cls): return cls.query.all() def delete(self): db.session.delete(self) db.session.commit() def save_to_db(self): db.session.add(self) db.session.commit()
class BedType(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255), nullable=False) accommodations = db.relationship("Accommodation", backref="bed_type", lazy=True) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) deleted_at = db.Column(db.DateTime)
class Amenity_category(db.Model): id = db.Column(db.Integer, primary_key=True) amenities = db.relationship('Amenity', backref='amenity_category', lazy=True) name = db.Column(db.String(255), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) deleted_at = db.Column(db.DateTime)
class Amenity(db.Model): id = db.Column(db.Integer, primary_key=True) amenity_category_id = db.Column(db.Integer, db.ForeignKey('amenity_category.id')) accommodations = db.relationship('Accommodation', secondary='link') name = db.Column(db.String(255), nullable=False) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) deleted_at = db.Column(db.DateTime)
class Accommodation(db.Model): id = db.Column(db.String(32), primary_key=True) likes = db.relationship('Like', backref='accommodation', lazy=True) promotions = db.relationship('Promotion', backref='accommodation', lazy=True) comments = db.relationship('Comment', backref='accommodation', lazy=True) images = db.relationship('Image', backref='accommodation', lazy=True) bookings = db.relationship('Booking', backref='accommodation', lazy=True) amenities = db.relationship('Amenity', secondary='link') member_id = db.Column(db.String(32), db.ForeignKey('member.id'), nullable=False) property_type_id = db.Column(db.Integer, db.ForeignKey('property_type.id'), nullable=False) room_type_id = db.Column(db.Integer, db.ForeignKey('room_type.id'), nullable=False) bed_type_id = db.Column(db.Integer, db.ForeignKey('bed_type.id')) name = db.Column(db.String(255), nullable=False) address = db.Column(db.String(255)) description = db.Column(db.Text) special_notices = db.Column(db.Text) status = db.Column(db.SmallInteger, nullable=False) standard_guess = db.Column(db.Integer, nullable=False) max_guess = db.Column(db.Integer, nullable=False) num_bathrooms = db.Column(db.SmallInteger) num_bedrooms = db.Column(db.SmallInteger) num_beds = db.Column(db.SmallInteger) apartment_manual = db.Column(db.Text) apartment_rule = db.Column(db.Text) direction_manual = db.Column(db.Text) checkin_guide = db.Column(db.Text) created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) updated_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) deleted_at = db.Column(db.DateTime) @classmethod def get_all_accommodation(cls): return cls.query.all() @classmethod def find_by_id(cls, _id): return cls.query.filter_by(id=_id).first() @classmethod def find_by_name(cls, name): return cls.query.filter_by(name=name).first() def save_to_db(self): db.session.add(self) db.session.commit() def delete(self): db.session.delete(self) db.session.commit()