from settings import *
class BaseModel(Model):
class Meta:
database = db
#设计数据表的时候有几个重要点一定要注意
"""
char类型, 要设置最大长度
对于无法确定最大长度的字段,可以设置为Text
设计表的时候 采集到的数据要尽量先做格式化处理
default和null=True
"""
class Product():
product_id = IntegerField(primary_key=True) # 产品识别ID
name = CharField(max_length=1000) # 产品名
#name = CharField(max_length=20,primary_key=True) # 产品名
price = FloatField(default=0.0) # 价格
#content = TextField(default="")
sales_num = IntegerField(default=0) # 销量
store_id = IntegerField() # 商家ID
#merchant = CharField() # 商家
store_Products = CharField(max_length=2000) # 主营
#merchant_Place = CharField(max_length=2000) # 地址
create_time = DateTimeField() # 抓取时间
class Product_attributes():
product_id = IntegerField(primary_key=True) # 产品识别ID
price_base = FloatField(default=0.0) # 基准价格
attributes = CharField(max_length=2000) # 商品描述
buyer_num = IntegerField(default=0) # 购买人数
sale_num = IntegerField(default=0) # 销售数量
buyer_rate = FloatField(default=0.0) # 商品复购率
create_time = DateTimeField() # 抓取时间
class Store():
store_id = IntegerField(primary_key=True) # 商户的id
store_name = CharField(max_length=2000) # 商户的名字
store_level = TextField(default="") # 商户的等级
store_place = CharField(max_length=2000) # 商户的地址
store_aptitude = CharField(max_length=2000) # 商户资质,保存的url链接
store_describe = CharField() # 商户描述
store_supply = CharField() # 商户供应
store_service = CharField() # 商户服务
create_time = DateTimeField() # 抓取时间
'''
class Product(BaseModel):
product_id = IntegerField(primary_key=True) # 产品识别ID
name = CharField(max_length=1000) # 产品名
#name = CharField(max_length=20,primary_key=True) # 产品名
price = FloatField(default=0.0) # 价格
#content = TextField(default="")
sales_num = IntegerField(default=0) # 销量
store_id = IntegerField() # 商家ID
#merchant = CharField() # 商家
store_Products = CharField(max_length=2000) # 主营
#merchant_Place = CharField(max_length=2000) # 地址
create_time = DateTimeField() # 抓取时间
class Product_attributes(BaseModel):
product_id = IntegerField(primary_key=True) # 产品识别ID
price_base = FloatField(default=0.0) # 基准价格
attributes = CharField(max_length=2000) # 商品描述
buyer_num = IntegerField(default=0) # 购买人数
sale_num = IntegerField(default=0) # 销售数量
buyer_rate = FloatField(default=0.0) # 商品复购率
create_time = DateTimeField() # 抓取时间
class Store(BaseModel):
store_id = IntegerField(primary_key=True) # 商户的id
store_name = CharField(max_length=2000) # 商户的名字
store_level = TextField(default="") # 商户的等级
store_place = CharField(max_length=2000) # 商户的地址
store_aptitude = CharField(max_length=2000) # 商户资质,保存的url链接
store_describe = CharField() # 商户描述
store_supply = CharField() # 商户供应
store_service = CharField() # 商户服务
create_time = DateTimeField() # 抓取时间
'''
class Catalogue(BaseModel): # 目录
_id = AutoField(primary_key=True) # 系列ID
_id.auto_increment = True
catalogue_name = CharField(max_length=2000) # 系列名称
catalogue_level = IntegerField(default=1) # 产品系列的等级
category_id = IntegerField(default=0) # 次级产品系列的ID,用来拼接url
father_id = IntegerField(default=0) # 上一层系列产品ID
create_time = DateTimeField() # 抓取时间
if __name__ == "__main__":
db.create_tables([Catalogue])
#db.create_tables([Topic, Answer, Author])
#db.create_tables([Product,Product_attributes,Store,Catalogue])