deliveryman-api/app/models/station.py
2025-01-08 09:52:41 +08:00

34 lines
1.0 KiB
Python

from typing import Optional
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
from sqlalchemy.sql import func
from pydantic import BaseModel, Field
from .database import Base
# 数据库模型
class StationDB(Base):
__tablename__ = "stations"
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(100), nullable=False)
community_id = Column(Integer, ForeignKey("communities.id"), index=True)
create_time = Column(DateTime(timezone=True), server_default=func.now())
update_time = Column(DateTime(timezone=True), onupdate=func.now())
# Pydantic 模型
class StationCreate(BaseModel):
name: str = Field(..., max_length=100)
community_id: int
class StationUpdate(BaseModel):
name: Optional[str] = Field(None, max_length=100)
community_id: Optional[int] = None
class StationInfo(BaseModel):
id: int
name: str
address: str
community_id: int
community_name: Optional[str] = None
class Config:
from_attributes = True