35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
"""城市码表:GB/T 2260 行政区划,三级(省 / 市 / 区县)。
|
||
|
||
选择器直接用这张表,用户资料里只存 code,名字跟着码表走——
|
||
码表由管理端维护,改名/停用都不影响历史数据的指向。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from datetime import datetime
|
||
|
||
from sqlalchemy import Boolean, DateTime, Integer, String, func
|
||
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
||
from app.db.session import Base
|
||
|
||
|
||
class Region(Base):
|
||
__tablename__ = "regions"
|
||
|
||
# 六位行政区划代码,省补 0000(330000),地级市补 00(330100)
|
||
code: Mapped[str] = mapped_column(String(12), primary_key=True)
|
||
name: Mapped[str] = mapped_column(String(64), index=True)
|
||
level: Mapped[int] = mapped_column(Integer, default=1) # 1 省 / 3 市辖区里的区 / 2 地级市
|
||
parent_code: Mapped[str | None] = mapped_column(String(12), index=True)
|
||
|
||
# 出生时间换算 UTC 要时区;港澳台与内地同属 UTC+8 但规则库分开更稳
|
||
timezone: Mapped[str] = mapped_column(String(64), default="Asia/Shanghai")
|
||
|
||
enabled: Mapped[bool] = mapped_column(Boolean, default=True)
|
||
sort_order: Mapped[int] = mapped_column(Integer, default=0)
|
||
|
||
updated_at: Mapped[datetime] = mapped_column(
|
||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||
)
|