lots of changes

This commit is contained in:
2026-03-21 07:32:43 -04:00
parent 21933cdef9
commit 47aeebd86f
7 changed files with 1463 additions and 107 deletions

58
db_models.py Normal file
View File

@@ -0,0 +1,58 @@
from sqlalchemy import Column, Integer, String, Float, ForeignKey
from sqlalchemy.orm import relationship
from .database import Base
class Location(Base):
"""
SQLAlchemy model for the 'locations' table.
"""
__tablename__ = "locations"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, unique=False, index=True)
address = Column(String, unique=False, index=True)
latitude = Column(Float, unique=False, index=True)
longitude = Column(Float, unique=False, index=True)
is_favorite = Column(Boolean, unique=False, index=True)
def __repr__(self):
return f"<Location(name='{self.name}', address='{self.address}', latitude='{self.latitude}', longitude='{self.longitude}', is_favorite='{self.is_favorite}')>"
class Route(Base):
"""
SQLAlchemy model for the 'routes' table.
"""
__tablename__ = "routes"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True)
# Start and Endpoints (One-to-Many relationship)
start_location_id = Column(Integer, ForeignKey('locations.id'))
end_location_id = Column(Integer, ForeignKey('locations.id'))
start_location = relationship("Location", foreign_keys=[start_id])
end_location = relationship("Location", foreign_keys=[end_id])
# Relationship to get waypoints ordered
waypoints = relationship("Waypoint", order_by="Waypoint.order", back_populates="route")
def __repr__(self):
return f"<Route(name='{self.name}', start='{self.start_location.name}', end='{self.end_location.name}')>"
# Association Table for Many-to-Many relationsjip (Routes <-> Waypoints)
class Waypoint(Base):
"""
SQLAlchemy model for the 'waypoints' table.
"""
__tablename__ = 'waypoints'
id = Column(Integer, primary_key=True)
route_id = Column(Integer, ForeignKey('routes.id'))
location_id = Column(Integer, ForeignKey('locations.id'))
order = Column(Integer, nullable=False)
route = relationship("Route", back_populates="waypoints")
location = relationship("Location")