backend/collectionObj/models.py
2025-05-14 16:31:46 +03:00

42 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import HTTPException
from sqlalchemy import Column, Integer, String, Float, Boolean, ForeignKey
from sqlalchemy.dialects.postgresql import ARRAY
from sqlalchemy.orm import Session, relationship, mapped_column, Mapped
from ..config import Base, get_session_db, user_collection, collection_item
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..auth.models import DBUser
from ..items.models import Items
##### veri tabanı modelleri #####
class CollectionsDB(Base):
__tablename__ = "collections_table"
collection_id : Mapped[int] = mapped_column(Integer, primary_key=True)
#user_id : Mapped[int] = mapped_column(Integer, ForeignKey("users_table.user_id"), nullable=False) # user_id ile ilişki
#item_id : Mapped[list[int]] = mapped_column(Integer, ForeignKey("items_table.item_id"), nullable=False) # item_id ile ilişki
visibility : Mapped[bool] = mapped_column(Boolean, default=True)
collection_name : Mapped[str] = mapped_column(String, nullable=False)
collection_description : Mapped[str] = mapped_column(String, default="No description")
# ilişkiler
users : Mapped['DBUser'] = relationship(
"DBUser",
secondary=user_collection,
back_populates="collections",
lazy='select'
) #back_populates karşı tarafın ismi
items : Mapped[list['Items']] = relationship(
"Items",
secondary=collection_item,
back_populates="collections" ,
lazy='select'
)
#### collection bir item listesi birde kullanıcı listesi tutacak