from enum import Enum from typing import Union, Optional, List, Dict # 导入pydantic对应的模型基类 from pydantic import BaseModel, constr, conint class GenderEnum(str, Enum): """ 性别枚举 """ male = "男" female = "女" class PydanticVerifyParam(BaseModel): """ 用来学习使用pydantic模型验...
from django.db import models from utils.base_model import BaseModel from users.models import User, Address from goods.models import GoodsSKU # Create your models here. class OrderInfo(BaseModel): """订单信息""" PAY_METHODS = { 1: "货到付款", 2: "支付宝", } PAY_METHODS_ENUM = { "...
fromenumimportEnum from typingimportList,Union from datetimeimportdate from pydanticimportBaseModelclassGender(str,Enum):man="man"women="women"classPerson(BaseModel):name:strgender:GenderclassDepartment(BaseModel):name:strlead:Personcast:List[Person]classGroup(BaseModel):owner:Personmember_list:List[Pers...
import uvicorn from enum import Enum app = FastAPI() class ModelName(str, Enum): alexnet = "alexnet" resnet = "resnet" lenet = "lenet" @app.get("/models/{model_name}") async def get_model(model_name: ModelName): if model_name == ModelName.alexnet: return {"model_name": model...
2.models文件夹下新建BaseModel.py,这样后面所有的model就可以继承这个基类,不用每个model再写单独的新增修改删除方法。 #!/usr/bin/python3#-*- coding: utf-8 -*-"""@Author : Huguodong @Version : --- @File : BaseModel.py @Description : ORM封装 @Create...
All database fields Custom manager attributes class Meta def (str) def save() def get_absolute_url() Any custom methods 1. 2. 3. 4. 5. 6. 7. (五)、异常捕获处理原则: 尽量只包含容易出错的位置,不要把整个函数 try catch 对于不会出现问题的代码,就不要再用 try catch了 ...
python3 内置的enum 模块可以支持枚举类型,此模块定义了四个枚举类,用来定义名称与值的唯一组合: Enum...
(str, Enum): + admin = "admin" + teacher = "teacher" + alumni = "alumni" + student = "student" + + +class UserProfile(BaseModel): + firstname: str + lastname: str + middle_initial: str + age: Optional[int] = 0 + salary: Optional[int] = 0 + birthday: date + user_type...
新增enum, mock, ipaddress, concurrent.futures, asyncio urllib, selector 不同枚举类间不能进行比较 同一枚举类间只能进行相等的比较 枚举类的使用(编号默认从1开始) 为了避免枚举类中相同枚举值的出现,可以使用@unique装饰枚举类 #枚举的注意事项 fromenumimport...