111111

from django.db import models
from tinymce.models import HTMLField

from db.model import BaseModel

Create your models here.

from django.contrib.auth.models import AbstractUser

class User(AbstractUser, BaseModel):
class Meta:
db_table = 'df_user'
verbose_name = '用户'
verbose_name_plural = verbose_name

class AddressManger(models.Manager):
# 得到默认的地址和得到所有的地址
def get_default_address(self, user): # 得到默认的地址
try:
address = self.get(user=user, is_default=True)
except self.model.DoesNotExist:
address = None
return address
def get_all_address(self, user): # 得到所有的地址
try:
have_address = self.filter(user=user) # filter
except self.model.DoesNotExist:
have_address = None
return have_address

class Address(models):
user = models.ForeignKey('User', verbose_name='所属者')
receiver = models.CharField(max_length=16, verbose_name='接收者')
addr = models.CharField(max_length=256, verbose_name='收货地址')
zip_code = models.IntegerField(max_length=6, null=True, verbose_name='邮编')
phone = models.IntegerField(max_length=11, verbose_name='收者电话')
# 不要忘了
is_default = models.BooleanField(default=False, verbose_name='是否默认')

obj = AddressManger()
class Meta:
    db_table = 'df_address'
    verbose_name = '订单地址'
    verbose_name_plural = verbose_name

class GoodsSKU(models):
"""商品SKU模型类"""
status_choices = (
(1, '上架'),
(0, '下架')
)
type = models.ForeignKey('Goods', verbose_name='商品种类', on_delete=models.CASCADE)
goods = models.ForeignKey('GoodsSPU', verbose_name='商品SPU', on_delete=models.CASCADE)
name = models.CharField(max_length=10, verbose_name='商品名称')
desc = models.CharField(max_length=256, verbose_name='商品描述')
price = models.DecimalField(max_length=10, decimal_places=2, verbose_name='商品价格')
image = models.ImageField(upload_to='goods', verbose_name='商品图片')
unite = models.IntegerField(max_length=20, verbose_name='商品单位')
stock = models.IntegerField(default=1, verbose_name='商品库存')
sales = models.IntegerField(default=0, verbose_name='商品销量')
isdefault = models.SmallIntegerField(default=1, verbose_name='默认选中')
class Meta:
db_table = 'df_goods_sku'
verbose_name = '商品SKU'
verbose_name_plural = verbose_name

class Goods(BaseModel):
"""商品种类模型类"""
name = models.CharField(max_length=20, verbose_name='商品种类')
logo = models.CharField(max_length=20, verbose_name='商品标识')
image = models.ImageField(upload_to='goods', verbose_name='商品图片')

class Meta:
    db_table = 'df_goods_tpye'
    verbose_name = '商品种类'
    verbose_name_plural = verbose_name

class GoodsSPU(BaseModel):
"""商品SPU模型类"""
name = models.CharField(max_length=20, verbose_name='商品名称')
detail = HTMLField(default=0, 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='商品SKU')
image = models.ImageField('goods', verbose_name='商品图片')

class Meta:
    db_table = 'df_goods_image'
    verbose_name = '商品图片'
    verbose_name_plural = verbose_name

class IndexTypeBrooner(BaseModel):

DISPLAY_STATUS = (
                (0, '标题'),
                (1,  '图片'),
                )

category = models.ForeignKey('Goods', verbose_name='商品种类')
sku = models.ForeignKey('GoodsSKU', verbose_name='商品SKU')
display_status = models.SmallIntegerField(choices=DISPLAY_STATUS, verbose_name='展示状态')
index = models.SmallIntegerField(default=1, verbose_name='展示顺序')

class Meta:
    db_table = 'df_goods_sku'
    verbose_name = '商品SKU'
    verbose_name_plural = verbose_name

class IndexBrooner(BaseModel):
'''首页轮询'''
sku = models.ForeignKey('GoodsSKU', verbose_name='商品SKU')
image = models.ImageField(upload_to='banner', verbose_name='轮询图片')
index = models.SmallIntegerField(default=1, verbose_name='展示顺序')

class Meta:
    db_table = 'df_goods_banner'
    verbose_name = '首页商品轮询'
    verbose_name_plural = verbose_name

class IndexPromotionBrooner(BaseModel):
name = models.CharField(max_length=10, verbose_name='活动名称')
title = models.CharField(max_length=10, verbose_name='活动标题')
image = models.ImageField(upload_to='banner', verbose_name='活动图片')
index = models.SmallIntegerField(default=1, verbose_name='展示顺序')

class Meta:
    db_table = 'df_promotion'
    verbose_name = '促销活动'
    verbose_name_plural = verbose_name

class OrderInfo(BaseModel):
'''订单信息模型类'''
PAY_METHODS = {
'1': '货到付款',
'2': '微信支付',
'3': '支付宝',
'4': '银联支付'
}
PAY_METHODS_CHOICES = (
('1', '货到付款'),
('2', '微信支付'),
('3','支付宝'),
('4','银联支付')
)
ORDER_STATUS = {
1:'待支付',
2:'待发货',
3:'待收货',
4:'待评价',
5:'已完成',
}
ORDER_STATUS_CHOICES = (
(1, '待支付'),
(2, '待发货'),
(3, '待收货'),
(4, '待评价'),
(5, '已完成')
)

order_id = models.CharField(max_length=10, verbose_name='订单id')
user = models.ForeignKey('user.User', verbose_name='用户')
addr = models.ForeignKey('user.Address', verbose_name='用户地址')

total_num = models.IntegerField(max_length=10, verbose_name='商品总数')
total_price = models.DecimalField(max_length=10, decimal_places=2, verbose_name='商品总价')
tirfic_order = models.DecimalField(max_length=10, decimal_places=2, verbose_name='订单运费')

pay_methods = models.SmallIntegerField(default=1, verbose_name='支付方式')
order_status = models.SmallIntegerField(default=1, verbose_name='订单状态')
# 忘了
trade_no = models.CharField(max_length=128, default='', verbose_name='支付编号')

class Meta:
    db_table = 'df_goods_sku'
    verbose_name = '商品SKU'
    verbose_name_plural = verbose_name

class OrderGoods(BaseModel):
'''
订单商品模型类
'''

order = models.ForeignKey('OrderInfo', verbose_name='订单信息')
goodsku = models.ForeignKey('GoodsSKU', verbose_name='商品信息')
price = models.DecimalField(max_length=20, decimal_places=2, verbose_name='价格')
num = models.IntegerField(max_length=10, verbose_name='数目')

class Meta:
    db_table = 'df_goods_sku'
    verbose_name = '商品SKU'
    verbose_name_plural = verbose_name
上一篇:Django+xadmin打造在线教育平台(四)


下一篇:表关系