官方文档研究 FastAPI Examples - Tortoise ORM v0.20.0 Documentation
网上好多教程都是手动封装Pydantic,不仅代码繁琐,后期改动也很麻烦,还是推荐使用ORM的模块,虽然会费事研究,但是后续提高开发效率。
对官方代码做了适当的改动,否则程序会报错
models.py
from tortoise import fields, models
from tortoise.contrib.pydantic import pydantic_model_creator
class Users(models.Model):
"""
The User model
"""
id = fields.IntField(pk=True)
#: This is a username
username = fields.CharField(max_length=20, unique=True)
name = fields.CharField(max_length=50, null=True)
family_name = fields.CharField(max_length=50, null=True)
category = fields.CharField(max_length=30, default="misc")
password_hash = fields.CharField(max_length=128, null=True)
created_at = fields.DatetimeField(auto_now_add=Tru


1万+

被折叠的 条评论
为什么被折叠?



