110 lines
4.5 KiB
Python
110 lines
4.5 KiB
Python
|
|
import uuid
|
|||
|
|
from tortoise import fields
|
|||
|
|
from tortoise.models import Model
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Shop(Model):
|
|||
|
|
"""
|
|||
|
|
店铺模型
|
|||
|
|
|
|||
|
|
字段:
|
|||
|
|
id (UUIDField): 主键,默认使用 UUID 生成
|
|||
|
|
province (CharField): 省份,最大长度 255
|
|||
|
|
city (CharField): 城市,最大长度 255
|
|||
|
|
street (CharField): 街道,最大长度 255
|
|||
|
|
shop_name (CharField): 店铺名称,最大长度 255
|
|||
|
|
shop_number (CharField): 店铺号码,最大长度 255, nullable 为 True
|
|||
|
|
"""
|
|||
|
|
id = fields.UUIDField(pk=True, default=uuid.uuid4, description="ID")
|
|||
|
|
province = fields.CharField(max_length=255, index=True, description="省份")
|
|||
|
|
city = fields.CharField(max_length=255, index=True, description="城市")
|
|||
|
|
street = fields.CharField(max_length=255, index=True, description="街道")
|
|||
|
|
shop_name = fields.CharField(max_length=255, index=True, description="店铺名称")
|
|||
|
|
shop_number = fields.CharField(max_length=255, null=True, description="店铺号码")
|
|||
|
|
create_time = fields.DatetimeField(auto_now_add=True, index=True, description='创建时间')
|
|||
|
|
update_time = fields.DatetimeField(auto_now=True, description='更新时间')
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Meta:
|
|||
|
|
table = "shop"
|
|||
|
|
table_description = "店铺表"
|
|||
|
|
ordering = ["create_time"]
|
|||
|
|
indexes = [
|
|||
|
|
("province", "city", "street"),
|
|||
|
|
]
|
|||
|
|
def __repr__(self):
|
|||
|
|
return f"<Shop(id={self.id}, province={self.province}, city={self.city}, street={self.street}, shop_name={self.shop_name})>"
|
|||
|
|
|
|||
|
|
__str__ = __repr__
|
|||
|
|
|
|||
|
|
class Food(Model):
|
|||
|
|
"""
|
|||
|
|
食物模型
|
|||
|
|
|
|||
|
|
字段:
|
|||
|
|
id (UUIDField): 主键,默认使用 UUID 生成
|
|||
|
|
name (CharField): 食物名称,最大长度 255
|
|||
|
|
"""
|
|||
|
|
id = fields.UUIDField(pk=True, default=uuid.uuid4, description="ID")
|
|||
|
|
name = fields.CharField(max_length=255, index=True, description="食物名称")
|
|||
|
|
create_time = fields.DatetimeField(auto_now_add=True, index=True, description='创建时间')
|
|||
|
|
update_time = fields.DatetimeField(auto_now=True, description='更新时间')
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Meta:
|
|||
|
|
table = "food"
|
|||
|
|
table_description = "食物表"
|
|||
|
|
ordering = ["create_time"]
|
|||
|
|
indexes = [
|
|||
|
|
("name",),
|
|||
|
|
]
|
|||
|
|
def __repr__(self):
|
|||
|
|
return f"<Food(id={self.id}, name={self.name})>"
|
|||
|
|
|
|||
|
|
__str__ = __repr__
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Info(Model):
|
|||
|
|
"""
|
|||
|
|
信息模型
|
|||
|
|
|
|||
|
|
字段:
|
|||
|
|
id (UUIDField): 主键,默认使用 UUID 生成
|
|||
|
|
firstname (CharField): 名,最大长度 255
|
|||
|
|
lastname (CharField): 姓,最大长度 255
|
|||
|
|
full_name (CharField): 全名,最大长度 255
|
|||
|
|
birthday (CharField): 生日(原始字符串),最大长度 32
|
|||
|
|
street_address (CharField): 街道地址,最大长度 255
|
|||
|
|
city (CharField): 城市,最大长度 255
|
|||
|
|
phone (CharField): 电话,最大长度 64
|
|||
|
|
zip_code (CharField): 邮编,最大长度 20
|
|||
|
|
state_fullname (CharField): 州全称,最大长度 255
|
|||
|
|
"""
|
|||
|
|
id = fields.UUIDField(pk=True, default=uuid.uuid4, description="ID")
|
|||
|
|
firstname = fields.CharField(max_length=255, index=True, description="名")
|
|||
|
|
lastname = fields.CharField(max_length=255, index=True, description="姓")
|
|||
|
|
full_name = fields.CharField(max_length=255, index=True, description="全名")
|
|||
|
|
birthday = fields.CharField(max_length=32, description="生日")
|
|||
|
|
street_address = fields.CharField(max_length=255, index=True, description="街道地址")
|
|||
|
|
city = fields.CharField(max_length=255, index=True, description="城市")
|
|||
|
|
phone = fields.CharField(max_length=64, description="电话")
|
|||
|
|
zip_code = fields.CharField(max_length=20, index=True, description="邮编")
|
|||
|
|
state_fullname = fields.CharField(max_length=255, index=True, description="州全称")
|
|||
|
|
status = fields.BooleanField(default=False, description="状态")
|
|||
|
|
create_time = fields.DatetimeField(auto_now_add=True, index=True, description='创建时间')
|
|||
|
|
update_time = fields.DatetimeField(auto_now=True, description='更新时间')
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Meta:
|
|||
|
|
table = "info"
|
|||
|
|
table_description = "信息表"
|
|||
|
|
ordering = ["create_time"]
|
|||
|
|
indexes = [
|
|||
|
|
("city", "zip_code", "state_fullname"),
|
|||
|
|
("firstname", "lastname"),
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
def __repr__(self):
|
|||
|
|
return f"<Info(id={self.id}, firstname={self.firstname}, lastname={self.lastname}, full_name={self.full_name}, birthday={self.birthday}, street_address={self.street_address}, city={self.city}, phone={self.phone}, zip_code={self.zip_code}, state_fullname={self.state_fullname})>"
|
|||
|
|
|
|||
|
|
__str__ = __repr__
|