|
| 1 | +from sqlalchemy import ForeignKey, String |
| 2 | +from sqlalchemy.orm import Mapped, mapped_column, relationship |
| 3 | + |
| 4 | +from app.core.models_core import CoreUser |
| 5 | +from app.types.sqlalchemy import Base |
| 6 | + |
| 7 | + |
| 8 | +class Item(Base): |
| 9 | + __tablename__ = "greencode_items" |
| 10 | + |
| 11 | + id: Mapped[str] = mapped_column(String, primary_key=True, index=True) |
| 12 | + qr_code_content: Mapped[str] = mapped_column(String, nullable=False, unique=True) |
| 13 | + title: Mapped[str] = mapped_column(String, nullable=False) |
| 14 | + content: Mapped[str] = mapped_column(String, nullable=False) |
| 15 | + users: Mapped[CoreUser] = relationship( |
| 16 | + "CoreUser", |
| 17 | + lazy="joined", |
| 18 | + back_populates="items", |
| 19 | + ) |
| 20 | + |
| 21 | + |
| 22 | +class Membership(Base): |
| 23 | + __tablename__ = "greencode_items" |
| 24 | + |
| 25 | + id: Mapped[str] = mapped_column(String, primary_key=True, nullable=False) |
| 26 | + item_id: Mapped[str] = mapped_column( |
| 27 | + ForeignKey("greencode_items.id"), |
| 28 | + primary_key=True, |
| 29 | + ) |
| 30 | + user_id: Mapped[str] = mapped_column( |
| 31 | + ForeignKey("coreuser.id"), |
| 32 | + primary_key=True, |
| 33 | + ) |
| 34 | + user: Mapped[CoreUser] = relationship( |
| 35 | + "CoreUser", |
| 36 | + lazy="joined", |
| 37 | + back_populates="greencode_items", |
| 38 | + ) |
0 commit comments