new database system
This commit is contained in:
parent
039b877241
commit
bf71979982
8 changed files with 92 additions and 124 deletions
42
collectionObj/models.py
Normal file
42
collectionObj/models.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
8
collectionObj/router.py
Normal file
8
collectionObj/router.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from fastapi import FastAPI, APIRouter
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/collections",
|
||||
tags=["collections"],
|
||||
responses={404: {"description": "Not found"}},
|
||||
dependencies=[],
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue