mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-14 10:47:30 +08:00
fix tortoise-orm error
external link update examples
This commit is contained in:
@ -1,94 +1,39 @@
|
||||
from tortoise import fields
|
||||
from tortoise import fields, Model
|
||||
|
||||
from . import BaseModel
|
||||
from .enums import AliYunSecretCategory, BaiduAiCategory, Status, DeviceSys
|
||||
from fastapi_admin.models import User as AdminUser
|
||||
from .enums import ProductType
|
||||
|
||||
|
||||
class User(AdminUser, BaseModel):
|
||||
last_login = fields.DatetimeField(description='上次登录')
|
||||
class User(AdminUser, Model):
|
||||
last_login = fields.DatetimeField(description='Last Login')
|
||||
is_active = fields.BooleanField(default=True, description='Is Active')
|
||||
avatar = fields.CharField(max_length=200)
|
||||
intro = fields.TextField()
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.pk}#{self.username}'
|
||||
|
||||
|
||||
class AliYunSecret(BaseModel):
|
||||
app_id = fields.CharField(max_length=50)
|
||||
app_secret = fields.CharField(max_length=50)
|
||||
category = fields.IntEnumField(AliYunSecretCategory, description='类别', default=AliYunSecretCategory.sms)
|
||||
|
||||
|
||||
class AliYunOss(BaseModel):
|
||||
bucket = fields.CharField(max_length=50, unique=True, description='仓库')
|
||||
domain = fields.CharField(max_length=200, description='域名')
|
||||
endpoint = fields.CharField(max_length=200, description='端点')
|
||||
aliyun_secret = fields.ForeignKeyField('models.AliYunSecret', related_name='aliyunoss')
|
||||
|
||||
|
||||
class App(BaseModel):
|
||||
uaid = fields.IntField(unique=True)
|
||||
label = fields.CharField(max_length=20)
|
||||
secret = fields.CharField(max_length=16, description='通信密钥')
|
||||
work_secret = fields.CharField(max_length=100, description='企业微信密钥')
|
||||
class Category(Model):
|
||||
slug = fields.CharField(max_length=200)
|
||||
name = fields.CharField(max_length=200)
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.uaid}#{self.label}'
|
||||
return f'{self.pk}#{self.name}'
|
||||
|
||||
|
||||
class AppSms(BaseModel):
|
||||
app = fields.ForeignKeyField('models.App', related_name='app_sms')
|
||||
scene = fields.CharField(max_length=50, description='使用场景')
|
||||
aliyun_secret = fields.ForeignKeyField('models.AliYunSecret', related_name='app_sms')
|
||||
sign_name = fields.CharField(max_length=20, description='签名')
|
||||
template_code = fields.CharField(max_length=20, description='模板编号')
|
||||
|
||||
class Meta:
|
||||
unique_together = (('app', 'scene'),)
|
||||
|
||||
|
||||
class BaiduAi(BaseModel):
|
||||
app_id = fields.CharField(max_length=50)
|
||||
api_key = fields.CharField(max_length=50)
|
||||
app_secret = fields.CharField(max_length=50)
|
||||
category = fields.IntEnumField(BaiduAiCategory, description='应用类别', default=BaiduAiCategory.id_card)
|
||||
class Product(Model):
|
||||
categories = fields.ManyToManyField('models.Category')
|
||||
name = fields.CharField(max_length=50)
|
||||
view_num = fields.IntField(description='View Num')
|
||||
sort = fields.IntField()
|
||||
is_reviewed = fields.BooleanField(description='Is Reviewed')
|
||||
type = fields.IntEnumField(ProductType, description='Product Type')
|
||||
image = fields.CharField(max_length=200)
|
||||
body = fields.TextField()
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.pk}#{self.app_id}'
|
||||
|
||||
|
||||
class AppBaiduAi(BaseModel):
|
||||
app = fields.ForeignKeyField('models.App', related_name='app_baidu_ais')
|
||||
baidu_ai = fields.ForeignKeyField('models.BaiduAi', related_name='app_baidu_ais')
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
label = fields.CharField(max_length=200)
|
||||
key = fields.CharField(max_length=20)
|
||||
value = fields.JSONField()
|
||||
status: Status = fields.IntEnumField(Status, default=Status.on, description='状态')
|
||||
|
||||
|
||||
class ApiLog(BaseModel):
|
||||
app = fields.ForeignKeyField('models.App', related_name='api_logs')
|
||||
endpoint = fields.CharField(max_length=50)
|
||||
success = fields.BooleanField(default=True, description='是否成功')
|
||||
status_code = fields.SmallIntField(description='状态码')
|
||||
|
||||
|
||||
class AppVersion(BaseModel):
|
||||
app = fields.ForeignKeyField('models.App', related_name='app_versions')
|
||||
channel = fields.CharField(max_length=20, description='渠道')
|
||||
device_sys = fields.IntEnumField(DeviceSys, default=DeviceSys.android, description='操作系统')
|
||||
version_code = fields.CharField(max_length=20, description='版本号')
|
||||
describe = fields.CharField(max_length=200, description='描述')
|
||||
download_url = fields.CharField(max_length=200, description='下载链接')
|
||||
is_update = fields.BooleanField(default=False, description='是否更新')
|
||||
|
||||
class Meta:
|
||||
ordering = ['-id']
|
||||
indexes = (('app', 'device_sys', 'channel'),)
|
||||
|
||||
|
||||
class ManyToManyTest(BaseModel):
|
||||
apps = fields.ManyToManyField('models.App')
|
||||
label = fields.CharField(max_length=200)
|
||||
return f'{self.pk}#{self.name}'
|
||||
|
Reference in New Issue
Block a user