updated admin page with more functionality, simplified burger menu and added many-to-many parent-child relationship
This commit is contained in:
@@ -19,5 +19,4 @@ class ChildResponse(BaseModel):
|
||||
name: str
|
||||
birth_time: datetime
|
||||
birth_weight: float
|
||||
user_id: int
|
||||
created_at: datetime
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Child database model."""
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from sqlalchemy import Column, Integer, String, DateTime, Float, ForeignKey
|
||||
from sqlalchemy import Column, Integer, String, DateTime, Float
|
||||
from datetime import datetime
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -21,8 +21,7 @@ class Child(Base):
|
||||
name = Column(String, nullable=False)
|
||||
birth_time = Column(DateTime, nullable=False)
|
||||
birth_weight = Column(Float, nullable=False) # in grams
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Child(id={self.id}, name='{self.name}', user_id={self.user_id})>"
|
||||
return f"<Child(id={self.id}, name='{self.name}')>"
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Child-Parent junction table for many-to-many relationship."""
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from sqlalchemy import Column, Integer, ForeignKey, DateTime
|
||||
from datetime import datetime
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
Base = DeclarativeBase
|
||||
else:
|
||||
from baby_monitor.repositories.dependencies.get_database import Base
|
||||
|
||||
|
||||
class ChildParent(Base):
|
||||
"""Junction table linking children to their parents (users)."""
|
||||
|
||||
__tablename__ = "child_parents"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
child_id = Column(Integer, ForeignKey("children.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<ChildParent(id={self.id}, "
|
||||
f"child_id={self.child_id}, user_id={self.user_id})>"
|
||||
)
|
||||
Reference in New Issue
Block a user