Ejemplo n.º 1
0
class House(db.Model):
	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.String(100), nullable=False)
	price = db.Column(db.Integer, nullable=False)
	house_type = db.Column(db.String(100), nullable=False)
	date_added = db.Column(db.DateTime, nullable=False, default=datetime.today)
	house_image = db.Column(db.String(20), nullable=False, default='house.jpg')
	description = db.Column(db.Text, nullable=False)
	user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

	def __repr__(self):
		return f"""House('{self.id}', '{self.name}', '{self.price}', '{self.house_type}', 
Ejemplo n.º 2
0
class Status(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    title = db.Column(db.String(40), nullable=False)

    products = db.relationship("Product", backref="status")

    def __repr__(self):
        return self.title
Ejemplo n.º 3
0
class User(db.Model, UserMixin):
	id = db.Column(db.Integer, primary_key=True)
	username = db.Column(db.String(20), unique=True, nullable=False)
	name = db.Column(db.String(60), nullable=False)
	email = db.Column(db.String(120), unique=True, nullable=False)
	gender = db.Column(db.String(20), nullable=False)
	user_type = db.Column(db.String(20),  nullable=False)
	user_image = db.Column(db.String(20), nullable=False, default='user.jpg')
	password = db.Column(db.String(60), nullable=False)
	houses = db.relationship('House', backref='owner', lazy=True)

	def get_reset_token(self, expires_sec=1800):
		s = Serializer(app.config['SECRET_KEY'], expires_sec)
		return s.dumps({'user_id': self.id}).decode('utf-8')

	@staticmethod
	def verify_reset_token(token):
		s = Serializer(app.config['SECRET_KEY'])
		try:
			user_id = s.loads(token)['user_id']
		except:
			return None
		return User.query.get(user_id)

	def __repr__(self):
		return f"""User('{self.id}', '{self.username}', '{self.name}', '{self.email}', 
Ejemplo n.º 4
0
class Product(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    title = db.Column(db.String(40), nullable=False)
    description = db.Column(db.Text(), nullable=False)
    short_description = db.Column(db.String(100), nullable=False)
    image = db.Column(db.String(500), nullable=False)
    price = db.Column(db.Integer(),nullable=False)
    created_at= db.Column(db.DateTime(timezone=True),server_default=func.now())
    is_published = db.Column(db.Boolean(), default=True, nullable=False)
    images = db.relationship("Images", backref="product")

    user_id = db.Column(db.Integer(),db.ForeignKey('user.id'))
    city_id=db.Column(db.Integer(),db.ForeignKey('city.id'))
    type_id=db.Column(db.Integer(),db.ForeignKey('type.id'))
    status_id = db.Column(db.Integer(), db.ForeignKey('status.id'))

    def __repr__(self):
        return self.title

    def getcity(self):
        return self.city.title()
Ejemplo n.º 5
0
class User(db.Model,UserMixin):
    id= db.Column(db.Integer,primary_key=True)
    username = db.Column(db.String(40),nullable=False)
    email = db.Column(db.String(40),nullable=False)
    first_name = db.Column(db.String(40),nullable=False)
    last_name = db.Column(db.String(40), nullable=False)
    phone_number = db.Column(db.String(10), nullable=False)
    # phone_country_code = db.Column(db.Unicode(10))
    password_hash = db.Column(db.String(255),nullable=False)
    is_active = db.Column(db.Boolean(),default=True,nullable=False)
    is_superuser = db.Column(db.Boolean(),default=False,nullable=False)
    date_joined= db.Column(db.DateTime(timezone=True),server_default=func.now())

    products = db.relationship("Product",backref="user")

    # phone_number = db.composite(
    #     PhoneNumber,
    #     _phone_number,
    #     phone_country_code
    # )

    def __init__(self,username,email,first_name,last_name,phone_number,password):
        self.username = username
        self.email = email
        self.first_name = first_name
        self.last_name = last_name
        self.phone_number=phone_number
        self.password_hash = generate_password_hash(password)

    def check_password(self,password):
        return check_password_hash(self.password_hash,password)

    def set_password(self,password):
        self.password_hash = generate_password_hash(password)

    def __repr__(self):
        return f'{self.first_name} {self.last_name}'
Ejemplo n.º 6
0
class Images(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    image = db.Column(db.String(500), nullable=False)

    product_id = db.Column(db.Integer(),db.ForeignKey('product.id'))