organization.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. Organization model - represents a client company.
  3. """
  4. from sqlalchemy import Boolean, String
  5. from sqlalchemy.orm import Mapped, mapped_column, relationship
  6. from app.models.base import Base
  7. class Organization(Base):
  8. """
  9. Organization (client company) model.
  10. Each organization can have multiple users and devices.
  11. Products (WiFi, BLE) are enabled/disabled per organization.
  12. """
  13. __tablename__ = "organizations"
  14. id: Mapped[int] = mapped_column(primary_key=True)
  15. name: Mapped[str] = mapped_column(String(255), nullable=False)
  16. contact_email: Mapped[str] = mapped_column(String(255), nullable=False)
  17. contact_phone: Mapped[str | None] = mapped_column(String(50))
  18. # Product access (modular)
  19. wifi_enabled: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
  20. ble_enabled: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
  21. # Status: pending, active, suspended, deleted
  22. status: Mapped[str] = mapped_column(
  23. String(20), default="pending", nullable=False
  24. )
  25. # Admin notes
  26. notes: Mapped[str | None] = mapped_column(String)
  27. # Relationships
  28. users: Mapped[list["User"]] = relationship(
  29. "User", back_populates="organization", cascade="all, delete-orphan"
  30. )
  31. devices: Mapped[list["Device"]] = relationship(
  32. "Device", back_populates="organization"
  33. )
  34. def __repr__(self) -> str:
  35. return f"<Organization {self.id}: {self.name}>"