• 天天生鲜(一) 表设计


    APP: goods

    from django.db import models
    from db.base_model import BaseModel
    from tinymce.models import HTMLField
    
    
    # Create your models here.
    
    
    # 商品类型
    class GoodsType(BaseModel):
        name = models.CharField(max_length=20, verbose_name='种类名称')
        logo = models.CharField(max_length=20, verbose_name='标识')
        image = models.ImageField(upload_to='type', verbose_name='商品类型图片')
    
        class Meta:
            db_table = 'df_goods_type'
            verbose_name = '商品种类'
            verbose_name_plural = verbose_name
    
        def __str__(self):
            return self.name
    
        # 获取类型下的商品
        def get_type_goods(self):
            return self.goodssku_set.all()
    
    
    # 商品SKU
    class GoodsSKU(BaseModel):
        status_choices = (
            (0, '下线'),
            (1, '上线'),
        )
        type = models.ForeignKey('GoodsType', verbose_name='商品种类')
        goods = models.ForeignKey('Goods', verbose_name='商品SPU')
        name = models.CharField(max_length=20, verbose_name='商品名称')
        desc = models.CharField(max_length=256, verbose_name='商品简介')
        price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品价格')
        unite = models.CharField(max_length=20, verbose_name='商品单位')
        image = models.ImageField(upload_to='goods', verbose_name='商品图片')
        stock = models.IntegerField(default=1, verbose_name='商品库存')
        sales = models.IntegerField(default=0, verbose_name='商品销量')
        status = models.SmallIntegerField(default=1, choices=status_choices, verbose_name='商品状态')
    
        class Meta:
            db_table = 'df_goods_sku'
            verbose_name = '商品'
            verbose_name_plural = verbose_name
    
        def __str__(self):
            return self.name
    
    
    # 商品SPU
    class Goods(BaseModel):
        name = models.CharField(max_length=20, verbose_name='商品SPU名称')
        # 富文本类型:带有格式的文本
        detail = HTMLField(blank=True, verbose_name='商品详情')
    
        class Meta:
            db_table = 'df_goods'
            verbose_name = '商品SPU'
            verbose_name_plural = verbose_name
    
    
    # 商品图片
    class GoodsImage(BaseModel):
        sku = models.ForeignKey('GoodsSKU', verbose_name='商品')
        image = models.ImageField(upload_to='goods', verbose_name='图片路径')
    
        class Meta:
            db_table = 'df_goods_image'
            verbose_name = '商品图片'
            verbose_name_plural = verbose_name
    
    
    # 首页轮播商品展示
    class IndexGoodsBanner(BaseModel):
        sku = models.ForeignKey('GoodsSKU', verbose_name='商品')
        image = models.ImageField(upload_to='banner', verbose_name='图片')
        index = models.SmallIntegerField(default=0, verbose_name='展示顺序')
    
        class Meta:
            db_table = 'df_index_banner'
            verbose_name = '首页轮播商品'
            verbose_name_plural = verbose_name
    
    
    # 首页分类商品展示(SKU)
    class IndexTypeGoodsBanner(BaseModel):
        DISPLAY_TYPE_CHOICES = (
            (0, "标题"),
            (1, "图片")
        )
    
        type = models.ForeignKey('GoodsType', verbose_name='商品类型')
        sku = models.ForeignKey('GoodsSKU', verbose_name='商品SKU')
        display_type = models.SmallIntegerField(default=1, choices=DISPLAY_TYPE_CHOICES, verbose_name='展示类型')
        index = models.SmallIntegerField(default=0, verbose_name='展示顺序')
    
        class Meta:
            db_table = 'df_index_type_goods'
            verbose_name = "主页分类展示商品"
            verbose_name_plural = verbose_name
    
    
    # 首页促销活动
    class IndexPromotionBanner(BaseModel):
        name = models.CharField(max_length=20, verbose_name='活动名称')
        url = models.URLField(verbose_name='活动链接')
        image = models.ImageField(upload_to='banner', verbose_name='活动图片')
        index = models.SmallIntegerField(default=0, verbose_name='展示顺序')
    
        class Meta:
            db_table = 'df_index_promotion'
            verbose_name = "主页促销活动"
            verbose_name_plural = verbose_name
    goods相关表

    APP: order

    from django.db import models
    from db.base_model import BaseModel
    
    
    # 订单模型类
    class OrderInfo(BaseModel):
        PAY_METHOD_CHOICES = (
            (1, '货到付款'),
            (2, '微信支付'),
            (3, '支付宝'),
            (4, '银联支付')
        )
    
        ORDER_STATUS_CHOICES = (
            (1, '待支付'),
            (2, '待发货'),
            (3, '待收货'),
            (4, '待评价'),
            (5, '已完成')
        )
    
        order_id = models.CharField(max_length=128, primary_key=True, verbose_name='订单id')
        user = models.ForeignKey('user.User', verbose_name='用户')
        address = models.ForeignKey('user.Address', verbose_name='地址')
        pay_method = models.SmallIntegerField(choices=PAY_METHOD_CHOICES, default=3, verbose_name='支付方式')
        total_count = models.IntegerField(default=1, verbose_name='商品数量')
        total_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品总价')
        transit_price = models.DecimalField(max_digits=10, decimal_places=2,verbose_name='订单运费')
        order_status = models.SmallIntegerField(choices=ORDER_STATUS_CHOICES, default=1, verbose_name='订单状态')
        trade_no = models.CharField(max_length=128, verbose_name='支付编号')
    
        class Meta:
            db_table = 'df_order_info'
            verbose_name = '订单'
            verbose_name_plural = verbose_name
    
        # 该订单下的所有商品
        def get_order_goods(self):
            return self.ordergoods_set.all()
    
    
    # 订单商品模型类
    class OrderGoods(BaseModel):
    
        order = models.ForeignKey('OrderInfo', verbose_name='订单')
        sku = models.ForeignKey('goods.GoodsSKU', verbose_name='商品SKU')
        count = models.IntegerField(default=1, verbose_name='商品数目')
        price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品价格')
        comment = models.CharField(max_length=256, verbose_name='评论')
    
        class Meta:
            db_table = 'df_order_goods'
            verbose_name = '订单商品'
            verbose_name_plural = verbose_name
    order相关表

    APP: user

    from django.db import models
    from django.contrib.auth.models import AbstractUser
    from db.base_model import BaseModel
    
    
    # 用户模型类
    class User(AbstractUser, BaseModel):
    
        class Meta:
            db_table = 'df_user'
            verbose_name = '用户'
            verbose_name_plural = verbose_name
    
    
    # 地址模型类
    class Address(BaseModel):
    
        user = models.ForeignKey('User', verbose_name='所属账户')
        receiver = models.CharField(max_length=20, verbose_name='收件人')
        address = models.CharField(max_length=256, verbose_name='收件地址')
        zip_code = models.CharField(max_length=6, null=True, verbose_name='邮政编码')
        phone = models.CharField(max_length=11, verbose_name='联系电话')
        is_default = models.BooleanField(default=False, verbose_name='是否默认')
    
        class Meta:
            db_table = 'df_address'
            verbose_name = '地址'
            verbose_name_plural = verbose_name
    user相关表
  • 相关阅读:
    关于工作流程引擎中的岗位的设置的问题
    将要发布的开源CCOA的照片一览
    关于多个checkbox在IE6下自由表单设计器中的兼容问题
    ccflow流程自动发起功能增加,如何按指定的时间触发方式发起流程?
    Windows 如何远程强行关机
    Report bulder
    微软sample and code down web address
    如何查看sql server的死锁情况
    如何读取数据的所有用户表
    复制和数据库镜像
  • 原文地址:https://www.cnblogs.com/yuqiangli0616/p/9883442.html
Copyright © 2020-2023  润新知