• 商品模块表结构分析


    1.表结构分析

    1.1 商品模块表结构分析

    from django.db import models
    
    # Create your models here.
    
    
    class Base(models.Model):
        create_time = models.TimeField(auto_now_add=True)
        update_time = models.TimeField(auto_now=True)
    
        class Meta:
            abstract = True
    
    # 商品表
    class Goods(Base):
        GOODS_TYPE = (
            ('1','Vip'),
            ('2','Course'),
        )
        CHANNEL_TYPE =(
            ('1','普通'),
            ('2','促销')
        )
    
        course = models.ForeignKey('course.Course',on_delete=models.PROTECT)
        goods_type = models.CharField(choices=GOODS_TYPE,max_length=8)
        produce_id = models.CharField('商品id',max_length=8)
        title = models.CharField('商品名称',max_length=24)
        price = models.DecimalField('商品价格',max_digits=8,decimal_places=2)
        channel_type = models.CharField('购买渠道',choices=CHANNEL_TYPE,max_length=8)
        period = models.CharField('购买渠道',max_length=365)
        is_launched = models.BooleanField(default=True)
    
        class Meta:
            db_table = 'goods'
    
        def __str__(self):
            return self.title
    
    # 订单表
    class Order(Base):
        PAY_METHOD = (
            (1, "支付宝"),
        )
        ORDER_STATUS=(
            (1, "待支付"),
            (2, "已支付"),
            (3, "已取消"),
        )
        user = models.ForeignKey('app01.User',on_delete=models.PROTECT)
        goods = models.ForeignKey(Goods,on_delete=models.PROTECT)
        order_id = models.CharField(max_length=24)
        trade_no = models.CharField(max_length=32,null=True)
        pay_time = models.DateTimeField(null=True)
        pay_method = models.CharField('支付方式', choices=PAY_METHOD, default=1, max_length=8)
        status = models.CharField('支付状态', choices=ORDER_STATUS, default=1, max_length=8)
        total_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="商品总金额")
    
        class Meta:
            db_table = 'tb_orders'
    
        def __str__(self):
            return self.order_id
    
    
    # 用户购买课程
    class User_Course(Base):
        user = models.ForeignKey('app01.User', on_delete=models.CASCADE, default=None, related_name='payuser')
        course = models.ForeignKey('course.Course', on_delete=models.CASCADE, related_name='paycourse',default=None)
    
        class Meta:
            db_table = 'usercourse'
    
    

    1.3 user/models.py添加VIP表并添加用户关联

    class Vip(Base):
        vip_choise = (
            ('0', '普通用户'),
            ('1', '普通会员'),
            ('2', '高级会员'),
        )
        title = models.CharField('vip名称', max_length=16)
        vip_type = models.CharField('Vip种类', choices=vip_choise, max_length=4)
        desc = models.CharField('vip描述', max_length=255)
        period = models.IntegerField('有效期', default=365)
    
        class Meta:
            db_table = 'tb_vip'
    
        def __str__(self):
            return self.title
    
    
    class User(AbstractUser):
    
        phone = models.CharField('手机号', max_length=20)
        img = models.ImageField(upload_to='user', null=True, blank=True)
        nick_name = models.CharField('昵称', max_length=20)	
        address = models.CharField('地址', max_length=255)
        vip = models.ForeignKey(Vip, on_delete=models.SET_NULL, default=None, null=True)
        vip_expiration = models.DateField('vip到期时间', blank=True, default=None, null=True)
    
        class Meta:
            db_table = 'tb_user'
            verbose_name_plural = '用户'
    

    2.在admin中注册

    2.1在goods/admin.py中注册

    from django.contrib import admin
    from .models import *
    # Register your models here.
    
    
    for model in [Goods,Order]:
        admin.site.register(model)
    

    2.2 在user/admin.py中注册

    from django.contrib import admin
    from .models import User,Vip
    # Register your models here.
    
    
    
    admin.site.register(User)
    admin.site.register(Vip)
    
  • 相关阅读:
    线程池优化之充分利用线程池资源
    Spring异步调用原理及SpringAop拦截器链原理
    使用pdfBox实现pdf转图片,解决中文方块乱码等问题
    Spring BPP中优雅的创建动态代理Bean
    转载:ThreadPoolExecutor 源码阅读
    Springboot定时任务原理及如何动态创建定时任务
    SpringSecurity整合JWT
    SpringMvc接口中转设计(策略+模板方法)
    HashMap 源码阅读
    支付宝敏感信息解密
  • 原文地址:https://www.cnblogs.com/Beginner-Y/p/13828555.html
Copyright © 2020-2023  润新知