from airtng_flask.models import app_db db = app_db() class VacationProperty(db.Model): __tablename__ = "vacation_properties" id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String, nullable=False) image_url = db.Column(db.String, nullable=False) host_id = db.Column(db.Integer, db.ForeignKey('users.id')) host = db.relationship("User", back_populates="vacation_properties") reservations = db.relationship("Reservation", back_populates="vacation_property") def __init__(self, description, image_url, host): self.description = description self.image_url = image_url self.host = host def __repr__(self): return '<VacationProperty {0} {1}>'.format(self.id, self.description)
from airtng_flask.models import app_db db = app_db() class VacationProperty(db.Model): __tablename__ = "vacation_properties" id = db.Column(db.Integer, primary_key=True) description = db.Column(db.String, nullable=False) image_url = db.Column(db.String, nullable=False) host_id = db.Column(db.Integer, db.ForeignKey('users.id')) host = db.relationship("User", back_populates="vacation_properties") reservations = db.relationship("Reservation", back_populates="vacation_property") def __init__(self, description, image_url, host): self.description = description self.image_url = image_url self.host = host def __repr__(self): return '<VacationProperty %r %r>' % self.id, self.description
from airtng_flask.models import app_db, auth_token, account_sid, phone_number, application_sid from flask import render_template from twilio.rest import Client DB = app_db() class Reservation(DB.Model): __tablename__ = "reservations" id = DB.Column(DB.Integer, primary_key=True) message = DB.Column(DB.String, nullable=False) status = DB.Column(DB.Enum('pending', 'confirmed', 'rejected', name='reservation_status_enum'), default='pending') anonymous_phone_number = DB.Column(DB.String, nullable=True) guest_id = DB.Column(DB.Integer, DB.ForeignKey('users.id')) vacation_property_id = DB.Column(DB.Integer, DB.ForeignKey('vacation_properties.id')) guest = DB.relationship("User", back_populates="reservations") vacation_property = DB.relationship("VacationProperty", back_populates="reservations") def __init__(self, message, vacation_property, guest): self.message = message self.guest = guest self.vacation_property = vacation_property self.status = 'pending' def confirm(self): self.status = 'confirmed' def reject(self): self.status = 'rejected'