24 lines
475 B
Python
24 lines
475 B
Python
import uuid
|
|
from typing import Optional, Union
|
|
|
|
from bson import ObjectId
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# # mongodb _id 类型
|
|
# class OId(ObjectId):
|
|
# @classmethod
|
|
# def __get_validators__(cls):
|
|
# yield cls.validate
|
|
#
|
|
# @classmethod
|
|
# def validate(cls, v):
|
|
# try:
|
|
# return ObjectId(v)
|
|
# except:
|
|
# raise ValueError('无效的格式')
|
|
|
|
|
|
class DBBase(BaseModel):
|
|
id: str = Field(None, alias='_id')
|