add updated_at fields

This commit is contained in:
2025-05-26 11:10:42 +02:00
parent 28db52dc2e
commit 5cd9d65e00
8 changed files with 438 additions and 4 deletions

View File

@@ -141,7 +141,7 @@ def update_shop(shop_id: int, shop_update: schemas.ShopUpdate, db: Session = Dep
if shop is None:
raise HTTPException(status_code=404, detail="Shop not found")
update_data = shop_update.dict()
update_data = shop_update.dict(exclude_unset=True)
for field, value in update_data.items():
setattr(shop, field, value)

View File

@@ -40,6 +40,7 @@ class Shop(Base):
city = Column(String, nullable=False)
address = Column(String, nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
# Relationships
shopping_events = relationship("ShoppingEvent", back_populates="shop")
@@ -53,6 +54,7 @@ class ShoppingEvent(Base):
total_amount = Column(Float, nullable=True) # Total cost of the shopping event
notes = Column(String, nullable=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
# Relationships
shop = relationship("Shop", back_populates="shopping_events")

View File

@@ -45,6 +45,7 @@ class ShopUpdate(BaseModel):
class Shop(ShopBase):
id: int
created_at: datetime
updated_at: Optional[datetime] = None
class Config:
from_attributes = True
@@ -87,6 +88,7 @@ class ShoppingEventUpdate(BaseModel):
class ShoppingEventResponse(ShoppingEventBase):
id: int
created_at: datetime
updated_at: Optional[datetime] = None
shop: Shop
groceries: List[GroceryWithEventData] = []