market页面
1.1 页面
进入该页面,默认跳出热销榜的商品,然后可以根据类型去排序,点击相应的按键会显示不同的内容
1.2 创建模型
页面左边的商品分类和主体区域的商品列表
models.py
class FoodType(models.Model):
typeid=models.IntegerField(default=1) #类型id
typenames=models.CharField(max_length=32) #类型名字
childtypenames=models.CharField(max_length=255) #子类型名字
typesort=models.IntegerField(default=1) #类型排序
class Meta:
db_table='sxw_foodtype'
class Goods(models.Model):
productid=models.IntegerField(default=1) #商品id
productimg=models.CharField(max_length=255) #图片
productname=models.CharField(max_length=128) #名字
productlongname=models.CharField(max_length=255) #长名字
isxf=models.BooleanField(default=False) #是否精选
pmdesc=models.BooleanField(default=False) #是否买一赠一
specifics=models.CharField(max_length=64) #规格
price=models.FloatField(default=0) #价格
marketprice=models.FloatField(default=0) #原价
categoryid=models.IntegerField(default=1) #商品组
childcid=models.IntegerField(default=1) #商品子组
childcidname=models.CharField(max_length=128) #商品子组名称
dealerid=models.IntegerField(default=1) #详情页id
storenums=models.IntegerField(default=1) #库存
productnum=models.IntegerField(default=1) #销量
class Meta:
db_table='axf_goods'
1.3 执行数据迁移,在数据库相应表中插入数据,写视图函数,渲染数据到前端。
views.py
def market(request):
foodtypes=FoodType.objects.all()
goods=Goods.objects.all()
data={
'foodtypes':foodtypes,
'goods':goods,
}