小米商城商品详情django+前端接口

模型类

from django.db import models


# Create your models here.
# 商品类别表:
# cate_name varchar(20)
class Category(models.Model):
    cate_name = models.CharField("类别名称", max_length=20)

    def __str__(self):
        return self.cate_name

    class Meta:
        db_table = "category"
        verbose_name_plural = "商品类别"


# 商品表
# sku_name:商品名字 varchar(100)
# price:价格 13,2
# selling_price:商品销售价格 13,2
# img:图片存放
class Goods(models.Model):
    sku_name = models.CharField("商品名字", max_length=100)
    price = models.DecimalField("价格", max_digits=13, decimal_places=2)
    selling_price = models.DecimalField("商品销售价格", max_digits=13, decimal_places=2)
    img = models.CharField("商品默认图片", max_length=200)
    title = models.CharField("商品标题", max_length=30)
    instruction = models.TextField("商品描述信息", default="")
    count = models.IntegerField("商品销量数量", default=0)
    stock = models.IntegerField("商品库存数量", default=0)
    cate = models.ForeignKey(to=Category, on_delete=models.CASCADE, verbose_name="商品类别")
    online = models.BooleanField("是否在售", default=True)

    def __str__(self):
        return self.sku_name

    class Meta:
        db_table = "goods"
        verbose_name_plural = "商品信息"


# 商品图片
class GoodImg(models.Model):
    img = models.CharField("图片地址", max_length=200)
    title = models.CharField("标题", max_length=20, null=True, blank=True)
    good = models.ForeignKey(to=Goods, on_delete=models.CASCADE, verbose_name="商品")

    def __str__(self):
        return "%s:%s" % (self.good.sku_name, self.img)

    class Meta:
        db_table = "goodimg"
        verbose_name_plural = "商品图片"


# 轮播图模型类
class Carousel(models.Model):
    imgPath = models.CharField("轮播图", max_length=200, null=False)
    describes = models.CharField("描述信息", max_length=200, null=False)

    def __str__(self):
        return "轮播图%s" % self.id

    class Meta:
        db_table = "carousel"
        verbose_name_plural = "轮播图"

配置路由

from django.urls import path
from goods import views

urlpatterns = [
    # 加载轮播图
    path("carousel/", views.CarouselAPIView.as_view()),
    # 加载一类商品
    path("oneCategory/all/", views.OneCategoryAPIView.as_view()),
    # 加载热门商品
    path("hotProduct/", views.HotProductAPIView.as_view()),
    # 商品详情
    path("detail/", views.GoodDetailAPIView.as_view()),
    # 商品详情轮播图
    path("detail/goodImg/", views.GoodDetailCarouselAPIView.as_view()),
    # 添加历史记录
    path("user/history/",views.HistoryAPIView.as_view())
]

模型视图

相关导包

import jwt
import redis
from django.conf import settings
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from goods.models import *
from functools import reduce

轮播图视图


                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值