Coverage for src / idx_api / models / brokerage_service_area.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2025-12-28 11:09 -0700

1"""BrokerageServiceArea model - defines service areas and featured areas for a brokerage.""" 

2 

3from typing import TYPE_CHECKING 

4 

5from sqlalchemy import Boolean, ForeignKey, Integer, String 

6from sqlalchemy.orm import Mapped, mapped_column, relationship 

7 

8from idx_api.models.base import Base, TimestampMixin 

9 

10if TYPE_CHECKING: 

11 from idx_api.models.brokerage import Brokerage 

12 

13 

14class BrokerageServiceArea(Base, TimestampMixin): 

15 """ 

16 Service areas for a brokerage. 

17 

18 Each brokerage can have multiple service areas (e.g., counties, cities). 

19 Some can be marked as "featured" to highlight on the homepage. 

20 """ 

21 

22 __tablename__ = "brokerage_service_areas" 

23 

24 id: Mapped[int] = mapped_column(primary_key=True) 

25 brokerage_id: Mapped[int] = mapped_column( 

26 ForeignKey("brokerages.id", ondelete="CASCADE"), nullable=False, index=True 

27 ) 

28 

29 # Area details 

30 name: Mapped[str] = mapped_column(String(200), nullable=False) # e.g., "Twin Falls County" 

31 slug: Mapped[str] = mapped_column(String(200), nullable=False) # e.g., "twin-falls-county" 

32 

33 # Whether this is a featured area (shown prominently on homepage) 

34 is_featured: Mapped[bool] = mapped_column(Boolean, default=False, server_default='0') 

35 

36 # Display order for sorting 

37 display_order: Mapped[int] = mapped_column(Integer, default=0, server_default='0') 

38 

39 # Relationships 

40 brokerage: Mapped["Brokerage"] = relationship(back_populates="service_areas") 

41 

42 def __repr__(self) -> str: 

43 return f"<BrokerageServiceArea(id={self.id}, name='{self.name}', brokerage_id={self.brokerage_id})>"