商品模組表結構分析

2022-08-24 18:12:13 字數 3654 閱讀 1637

商品模組表結構分析

from django.db import models

from utils.mybasemodel import base

​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)

product_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)

period = models.integerfield('有效期', default=365)

is_launched = models.booleanfield('是否上架', default=true)

class meta:

db_table = 'tb_goods'

def __str__(self):

return self.title

class orders(base):

pay_method = (

(1, '支付寶'),

)order_status = (

(1, '待支付'),

(2, '已支付'),

(3, '已取消'),

)user = models.foreignkey('user.user', on_delete=models.protect, verbose_name='下單使用者')

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

course/models.py中新增使用者購買課程

class usercourse(base):

user = models.foreignkey('user.user', on_delete=models.cascade, related_name='paycourse')

course = models.foreignkey('course.course', on_delete=models.cascade, related_name='payuser')

class meta:

db_table = 'tb_usercourse'

def __str__(self):

return "使用者:%s, 課程:%s" % (self.user.username, self.course.title)

user/models.py新增vip表並新增使用者關聯

from django.db import models

from utils.mybasemodel import base

​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)

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'

admin.py中註冊

#goods/admin

from django.contrib import admin

from . import models

​admin.site.register(models.goods)

admin.site.register(models.orders)​​

​​# user/admin

from django.contrib import admin

from user import models

​admin.site.register(models.user)

admin.site.register(models.vip)

商品模組表結構分析

from django.db import models create your models here.class base models.model create time models.timefield auto now add true update time models.timefie...

01 商品模組表結構分析

1.表結構分析 1.1 商品模組表結構分析 from django.db import models from utils.mybasemodel import base class goods base goods type 1 vip 2 course channel type 1 普通 2 c...

商品模組表結構分析 1

1.表結構分析 1.1 商品模組表結構分析 from django.db import models from utils.mybasemodel import base class goods base goods type 1 vip 2 course channel type 1 普通 2 c...