-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
67 lines (52 loc) · 2.19 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
@Time : 2024/1/8 11:01
@Author : zhaowanpeng
@Desc : None
"""
from tortoise import fields, models
from tortoise.validators import RegexValidator
from tortoise.contrib.pydantic import pydantic_model_creator
from user_module.utils import regex_patterns
import re
class Users(models.Model):
"""
The User model
"""
id = fields.IntField(pk=True)
username = fields.CharField(unique=True, index=True, max_length=20,
validators=[RegexValidator(regex_patterns.username, re.I)])
phone = fields.CharField(null=True, index=True, max_length=11,
validators=[RegexValidator(regex_patterns.phone, re.I)])
email = fields.CharField(null=True, index=True, max_length=50,
validators=[RegexValidator(regex_patterns.email, re.I)])
# salt = fields.CharField()
password = fields.CharField(max_length=10)
deleted = fields.BooleanField(default=False) # 是否注销
banned = fields.BooleanField(default=False) # 是否被禁
phone_active = fields.BooleanField(default=False)
email_active = fields.BooleanField(default=False)
created_at = fields.DatetimeField(null=True, auto_now_add=True)
updated_at = fields.DatetimeField(null=True, auto_now=True)
"""
生成pytandic
"""
# def full_name(self) -> str:
# """
# Returns the best name
# """
# if self.name or self.family_name:
# return f"{self.name or ''} {self.family_name or ''}".strip()
# return self.username
# class PydanticMeta:
# computed = ["full_name"]
# exclude = ["password_hash","created_at","modified_at"]
User_Pydantic = pydantic_model_creator(Users, name="User")
UserOut_Pydantic = pydantic_model_creator(Users, name="UserOut", include=("id","username","phone","email",))
UserIn_Pydantic = pydantic_model_creator(Users, name="UserIn", include=("username","phone","email","password"))#exclude=("id","created_at","updated_at")
print("--start--"*10)
print(UserIn_Pydantic.model_json_schema())
print("--end--"*10)
# exit()
# UserIn_Pydantic = pydantic_model_creator(Users, name="UserIn", exclude_readonly=True)
# print(123)