deliveryman-api/app/models/station.py
2025-02-13 11:24:07 +08:00

35 lines
1.1 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 typing import Optional
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, DECIMAL
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(50), nullable=False)
service_text = Column(String(50), nullable=False, server_default="服务时间8:3020:30")
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
community_id: int
community_name: Optional[str] = None
service_text: str
class Config:
from_attributes = True