generated from gilles/template-webapp
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""Modèle SQLAlchemy pour les boutiques/magasins.
|
|
|
|
Les boutiques représentent les lieux d'achat des objets.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import DateTime, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.core.database import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.item import Item
|
|
|
|
|
|
class Shop(Base):
|
|
"""Boutique ou magasin.
|
|
|
|
Attributes:
|
|
id: Identifiant unique auto-incrémenté
|
|
name: Nom de la boutique (ex: "Amazon", "Leroy Merlin")
|
|
description: Description optionnelle
|
|
url: URL du site web de la boutique
|
|
address: Adresse physique optionnelle
|
|
created_at: Date/heure de création (auto)
|
|
updated_at: Date/heure de dernière modification (auto)
|
|
items: Relation vers les objets achetés dans cette boutique
|
|
"""
|
|
|
|
__tablename__ = "shops"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(200), unique=True, nullable=False, index=True)
|
|
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
url: Mapped[str | None] = mapped_column(String(500), nullable=True)
|
|
address: Mapped[str | None] = mapped_column(Text, nullable=True)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False
|
|
)
|
|
updated_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True),
|
|
server_default=func.now(),
|
|
onupdate=func.now(),
|
|
nullable=False,
|
|
)
|
|
|
|
items: Mapped[list["Item"]] = relationship(
|
|
"Item", back_populates="shop"
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<Shop(id={self.id}, name='{self.name}')>"
|