class BaseModle(models.Model):
name = models.CharField(max_length=32, unique=True)
# 商品分类状态 1为上架 0 为下架
status = models.SmallIntegerField(default=0)
# 添加时间
addtime = models.DateTimeField(auto_now_add=True)
class Meta:
#抽象
abstract = True
class Category(BaseModle):
pass
class Meta:
db_table = ‘category‘ #指定表名
class Goods(BaseModle):
#商品图片
img = models.CharField(max_length=255)
#商品价格 最长9位保留两位小数
price = models.DecimalField(max_digits=9,decimal_places=2)
#商品分类外键 级联删除 一对多关系
cate = models.ForeignKey(‘Category‘,on_delete=models.CASCADE)
class Meta:
db_table = ‘goods‘
python manage.py makemigrations
python manage.py migrate