34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
from pydantic import BaseModel as BModel
|
|
from pydantic import Field
|
|
|
|
from model.field_type import IntStr
|
|
|
|
|
|
class BaseModel(BModel):
|
|
@classmethod
|
|
def get_fields(cls):
|
|
return [v.alias for v in cls.__fields__.values()]
|
|
|
|
|
|
class GBaseModel(BaseModel):
|
|
platform: str = Field(None, title="平台", alias='_platform')
|
|
channel_name: str = Field(..., min_length=1, title="channel", alias='_channel_name')
|
|
owner_name: str = Field(..., min_length=1, title="owner", alias='_owner_name')
|
|
channel_uid: str = Field(..., min_length=1, title="channel_uid", alias='_channel_uid')
|
|
device_id: str = Field(..., min_length=1, title='device_id', alias='_device_id')
|
|
district_server_id: int = Field(..., title="区服id", alias='_district_server_id')
|
|
game_role_id: str = Field(..., min_length=1, title="角色id", alias='_game_role_id')
|
|
event_time: int = Field(..., title="事件时间", alias='_event_time')
|
|
role_level: int = Field(None, title="角色等级")
|
|
role_vip: int = Field(None, title="角色vip等级")
|
|
role_stage: IntStr = Field(None, title="关卡")
|
|
role_create_time: int = Field(None, title="角色创建时间")
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
obj = GBaseModel(_id="5fd0f4812de17aeba6c1a373", role_level='2', aaa=123, _platform=13566, _event_time=123456789)
|
|
print(GBaseModel.get_fields())
|
|
print(obj.dict(by_alias=True))
|