Initial Commit
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Float, Text, DateTime, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from database import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
username = Column(String(50), unique=True, index=True)
|
||||
email = Column(String(100), unique=True, index=True, nullable=True)
|
||||
hashed_password = Column(String(60))
|
||||
full_name = Column(String(100), nullable=True)
|
||||
phone = Column(String(20), nullable=True)
|
||||
is_agent = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||
|
||||
properties = relationship("Property", back_populates="owner")
|
||||
favorites = relationship("Favorite", back_populates="user")
|
||||
|
||||
|
||||
class Property(Base):
|
||||
__tablename__ = "properties"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String(200), nullable=False)
|
||||
description = Column(Text, nullable=False)
|
||||
price = Column(Integer, nullable=False)
|
||||
property_type = Column(String(50), nullable=False)
|
||||
bedrooms = Column(Integer, default=0)
|
||||
bathrooms = Column(Float, default=0)
|
||||
area_sqft = Column(Integer, nullable=False)
|
||||
address = Column(String(300), nullable=False)
|
||||
city = Column(String(100), nullable=False)
|
||||
state = Column(String(50), nullable=False)
|
||||
zip_code = Column(String(10), nullable=False)
|
||||
year_built = Column(Integer, nullable=True)
|
||||
status = Column(String(20), default="active")
|
||||
is_featured = Column(Boolean, default=False)
|
||||
contact_email = Column(String(100), nullable=True)
|
||||
contact_phone = Column(String(30), nullable=True)
|
||||
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||
updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc),
|
||||
onupdate=lambda: datetime.now(timezone.utc))
|
||||
|
||||
owner_id = Column(Integer, ForeignKey("users.id"))
|
||||
owner = relationship("User", back_populates="properties")
|
||||
images = relationship("PropertyImage", back_populates="property", cascade="all, delete-orphan")
|
||||
favorites = relationship("Favorite", back_populates="property")
|
||||
|
||||
|
||||
class PropertyImage(Base):
|
||||
__tablename__ = "property_images"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
image_path = Column(String(500), nullable=False)
|
||||
is_primary = Column(Boolean, default=False)
|
||||
sort_order = Column(Integer, default=0)
|
||||
|
||||
property_id = Column(Integer, ForeignKey("properties.id"))
|
||||
property = relationship("Property", back_populates="images")
|
||||
|
||||
|
||||
class Favorite(Base):
|
||||
__tablename__ = "favorites"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
property_id = Column(Integer, ForeignKey("properties.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc))
|
||||
|
||||
user = relationship("User", back_populates="favorites")
|
||||
property = relationship("Property", back_populates="favorites")
|
||||
|
||||
__table_args__ = (UniqueConstraint("user_id", "property_id", name="uq_user_property"),)
|
||||
Reference in New Issue
Block a user