1.在settings中配置:python
AUTH_USER_MODEL='users.UserProfile'
2.apps/users/models.py中創建UserProfile表:git
class UserProfile(AbstractUser): """ 用戶表 """ nickName=models.CharField(max_length=30,default=‘’,verbose_name='微信名') avatarUrl = models.CharField(max_length=200, null=True, blank=True, verbose_name='用戶頭像URL') open_id = models.CharField(max_length=64, null=True, blank=True, verbose_name='OpenId') token = models.CharField(max_length=64, null=True, blank=True, verbose_name='token') gender = models.CharField(max_length=4, choices=(('0', '未知'), ('1', '男'), ('2', '女')), default='0', verbose_name='性別') city = models.CharField(max_length=20, null=True, blank=True, verbose_name='用戶所在市') longitude = models.CharField(max_length=10, null=True, blank=True, verbose_name='經度') latitude = models.CharField(max_length=10, null=True, blank=True, verbose_name='緯度') jifen=models.IntegerField(default=0,verbose_name='積分') yongjin=models.FloatField(default=0,verbose_name='佣金') fensi_num=models.IntegerField(default=0,verbose_name='粉絲數') class Meta: verbose_name='用戶' verbose_name_plural = verbose_name
def __str__(self):
return self.nickName
3.執行數據更新命令:django
python manage.py makemigrations
python manage.py migrate
1.在apps/users/models.py中創建地區表:小程序
class Area(models.Model): """ 地區表 """ CATEGORY_TYPE = ( (1, '省級'), (2, '市級'), (3, '區縣級'), ) num=models.IntegerField(default=0,verbose_name='地區編碼') name = models.CharField(default='', max_length=30, verbose_name='地名') category_type = models.IntegerField(choices=CATEGORY_TYPE, verbose_name='地區級別') parent_category = models.ForeignKey('self', null=True, blank=True, verbose_name='父類目錄', related_name='sub_cat', on_delete=models.CASCADE) add_time = models.DateTimeField(default=datetime.now, verbose_name='添加時間') class Meta: verbose_name = '地區' verbose_name_plural = verbose_name def __str__(self): return self.name
2.執行數據更新命令:微信
python manage.py makemigrations
python manage.py migrate
1.在apps/users/models.py中創建 用戶增長積分表:app
class AddJiFen(models.Model): """用戶增長積分表""" user = models.ForeignKey(UserProfile, verbose_name="用戶", on_delete=models.CASCADE) ad_jifen = models.IntegerField(default=0, verbose_name='積分') add_time = models.DateTimeField(default=datetime.now, verbose_name='添加時間') class Meta: verbose_name = '用戶增長積分表' verbose_name_plural = verbose_name def __str__(self): return self.user.nickName
2.執行數據更新命令:編碼
python manage.py makemigrations
python manage.py migrate
1.安裝處理圖片的依賴包pillow:url
pip install pillow
2.在apps/ad/models.py中:spa
from django.db import models
from datetime import datetime
from users.models import UserProfile,Area
from django.utils.safestring import mark_safe
# Create your models here.
class Category(models.Model):
"""
分類表
"""
name=models.CharField(default='',max_length=30,verbose_name='類別名')
category_type=models.IntegerField(choices=((1, '一級類目'),(2, '二級類目')),verbose_name='類別級別')
parent_category=models.ForeignKey('self',null=True,blank=True,verbose_name='父類目錄',related_name='sub_cat',on_delete=models.CASCADE)
is_tab=models.BooleanField(default=False,verbose_name='是否導航',help_text='是否導航')
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加時間')
class Meta:
verbose_name='類別'
verbose_name_plural=verbose_name
def __str__(self):
return self.name
class Good(models.Model):
"""廣告或店鋪"""
title=models.CharField(max_length=15,null=True,blank=True,verbose_name='標題',help_text='最多15字')
desc = models.TextField(default='', max_length=400, verbose_name='描述',help_text='最多400字')
address = models.CharField(max_length=200, default="", verbose_name="詳細地址")
mobile = models.CharField(max_length=11, default="", verbose_name="電話")
pv = models.IntegerField(default=0, verbose_name='瀏覽量')
category = models.ForeignKey(Category, verbose_name="分類", on_delete=models.CASCADE)
area = models.ForeignKey(Area, null=True, blank=True, verbose_name="地區", on_delete=models.CASCADE)
stage = models.IntegerField(default=1, choices=((1, '待審覈'),(2, '已發佈'),(3,'未經過')), verbose_name="階段")
user = models.ForeignKey(UserProfile, verbose_name="發佈者", on_delete=models.CASCADE)
type = models.IntegerField(default=1, choices=((1, '廣告'), (2, '店鋪')), verbose_name="類型")
image = models.ImageField(max_length=200,default='smallapp/1.png', upload_to='smallapp/',verbose_name='小程序碼')
last_visit_time=models.DateTimeField(default=datetime.now, verbose_name='最後瀏覽時間')
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加時間')
xian_top=models.IntegerField(default=0, choices=((0,'未置頂'),(1, '置頂'),(2, '超級置頂')), verbose_name="是否縣置頂")
shi_top = models.IntegerField(default=0, choices=((0, '未置頂'), (1, '置頂'), (2, '超級置頂')), verbose_name="是否市置頂")
sheng_top = models.IntegerField(default=0, choices=((0, '未置頂'), (1, '置頂'), (2, '超級置頂')), verbose_name="是否省置頂")
class Meta:
verbose_name = "發佈廣告或店鋪"
verbose_name_plural = verbose_name
def __str__(self):
return self.title
def image_url(self):
return mark_safe('<img src="/media/{0}" class="field_img">'.format(self.image))
image_url.short_description = '小程序碼'
class Prize(models.Model):
"""獎品"""
title = models.CharField(max_length=15, null=True, blank=True, verbose_name='標題', help_text='最多15字')
url=models.CharField(max_length=200, null=True, blank=True, verbose_name='小程序url')
area = models.ForeignKey(Area, null=True, blank=True, verbose_name="地區", on_delete=models.CASCADE)
get_num=models.IntegerField(default=0,verbose_name='被領取數')
price = models.IntegerField(default=0, verbose_name='所需積分')
all_num=models.IntegerField(default=0,verbose_name='發佈數')
desc = models.TextField(default='', max_length=400, verbose_name='描述', help_text='最多400字')
usage = models.TextField(default='', max_length=200, verbose_name='使用方式', help_text='最多200字')
image = models.ImageField(max_length=200, default='', upload_to='prizeimg/', verbose_name='獎品圖片')
end_time = models.DateTimeField(default=datetime.now, verbose_name='過時時間')
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加時間')
class Meta:
verbose_name = "獎品"
verbose_name_plural = verbose_name
def __str__(self):
return self.title
def image_url(self):
return mark_safe('<img src="/media/{0}" class="field_img">'.format(self.image))
image_url.short_description = '獎品圖片'
class Images(models.Model):
"""
圖片
"""
is_banner=models.BooleanField(default=False,verbose_name='是不是輪播圖')
image = models.ImageField(max_length=200, upload_to='images/')
good = models.ForeignKey(Good, verbose_name="廣告或店鋪",blank=True,null=True, on_delete=models.CASCADE)
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加時間')
class Meta:
verbose_name = "圖片"
verbose_name_plural = verbose_name
def image_url(self):
return mark_safe('<img src="/media/{0}" class="field_img">'.format(self.image))
image_url.short_description = '圖片'
class Top(models.Model):
"""
置頂表
"""
good = models.ForeignKey(Good, verbose_name="廣告或店鋪",blank=True,null=True, on_delete=models.CASCADE)
xian_end_time = models.DateTimeField(default=datetime.now, verbose_name='縣置頂截止時間')
shi_end_time = models.DateTimeField(default=datetime.now, verbose_name='市置頂截止時間')
sheng_end_time = models.DateTimeField(default=datetime.now, verbose_name='省置頂截止時間')
super_xian_end_time = models.DateTimeField(default=datetime.now, verbose_name='縣超級置頂截止時間')
super_shi_end_time = models.DateTimeField(default=datetime.now, verbose_name='市超級置頂截止時間')
super_sheng_end_time = models.DateTimeField(default=datetime.now, verbose_name='省超級置頂截止時間')
add_time = models.DateTimeField(default=datetime.now, verbose_name='添加時間')
class Meta:
verbose_name = "置頂表"
verbose_name_plural = verbose_name
def __str__(self):
return self.good.title
3.執行數據更新命令:設計
python manage.py makemigrations
python manage.py migrate
1.apps/trade/models.py中:
from django.db import models from datetime import datetime from users.models import UserProfile,Area from ad.models import Good # Create your models here. class Price(models.Model): """置頂服務價格表""" top_type = models.CharField(max_length=4, choices=(('0', '置頂'), ('1', '超級置頂')), default='0',verbose_name='置頂類型') price=models.FloatField(default=0,verbose_name="價格") fanwei=models.CharField(max_length=4, choices=(('0', '全縣'), ('1', '全市'),('2', '全省')), default='0',verbose_name='置頂類型') days=models.IntegerField(default=0,verbose_name='天數') add_time = models.DateTimeField(default=datetime.now, verbose_name='添加時間') class Meta: verbose_name = '置頂服務價格表' verbose_name_plural = verbose_name def __str__(self): return "%s-%s(%d)".format(self.top_type,self.fanwei, self.days) class Order(models.Model): """置頂訂單""" user = models.ForeignKey(UserProfile, verbose_name="購買者", on_delete=models.CASCADE) good=models.ForeignKey(Good,null=True, blank=True, verbose_name="廣告或店鋪", on_delete=models.CASCADE) order_sn = models.CharField(max_length=32, null=True, blank=True, unique=True, verbose_name="訂單號") pay_status = models.CharField(choices=(("TRADE_SUCCESS", "成功"),("TRADE_CLOSED", "超時關閉"),("paying", "待支付")), default="paying", max_length=30, verbose_name="訂單狀態") trade_no = models.CharField(max_length=100, unique=True, null=True, blank=True, verbose_name="交易號") order_mount = models.FloatField(default=0.0, verbose_name="訂單金額") pay_time = models.DateTimeField(null=True, blank=True, verbose_name="支付時間") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加時間") class Meta: verbose_name = "訂單表" verbose_name_plural = verbose_name def __str__(self): return str(self.order_sn) class ShoppingCar(models.Model): """購物車表(置頂)""" user = models.ForeignKey(UserProfile, verbose_name="購買者", on_delete=models.CASCADE) order = models.ForeignKey(Order, verbose_name="訂單", on_delete=models.CASCADE) top_good=models.ForeignKey(Price, verbose_name="置頂服務種類",related_name="goods", on_delete=models.CASCADE) goods_num = models.IntegerField(default=1, verbose_name="置頂服務數量",help_text='目前只支持每次每種置頂服務購買數量爲1') price=models.FloatField(default=0.0, verbose_name="訂單金額") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加時間") class Meta: verbose_name = "購物車表" verbose_name_plural = verbose_name
2.執行數據更新命令:
python manage.py makemigrations
python manage.py migrate
1.apps/user_operation/models.py中:
from django.db import models from datetime import datetime from users.models import UserProfile from ad.models import Prize # Create your models here. class Message(models.Model): """用戶消息表""" user = models.ForeignKey(UserProfile, verbose_name="用戶", on_delete=models.CASCADE) content=models.TextField(default='', max_length=200, verbose_name='消息內容',help_text='最多200字') is_read=models.BooleanField(default=False,verbose_name="是否已讀") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加時間") class Meta: verbose_name = "用戶消息表" verbose_name_plural = verbose_name def __str__(self): return self.content class GetPrize(models.Model): """兌獎表""" user = models.ForeignKey(UserProfile, verbose_name="用戶", on_delete=models.CASCADE) prize=models.ForeignKey(Prize, verbose_name="獎品", on_delete=models.CASCADE) status = models.CharField(choices=(("0", "待發貨"), ("1", "已發貨"), ("2", "已簽收")),default="0", max_length=8, verbose_name="獎品發放狀態") add_time = models.DateTimeField(default=datetime.now, verbose_name="添加時間") class Meta: verbose_name = "兌獎表" verbose_name_plural = verbose_name def __str__(self): return self.prize class UserAdress(models.Model): """用戶收貨地址""" user = models.ForeignKey(UserProfile, verbose_name="用戶", on_delete=models.CASCADE) address=models.CharField(max_length=300,verbose_name='收貨地址',default='',help_text='最多300字') phone=models.CharField(max_length=11,verbose_name='電話',default='') name=models.CharField(max_length=15,verbose_name='收件人',default='') add_time = models.DateTimeField(default=datetime.now, verbose_name="添加時間") class Meta: verbose_name = "用戶收貨地址" verbose_name_plural = verbose_name def __str__(self): return self.name class Fans(models.Model): """粉絲表""" user=models.ForeignKey(UserProfile, verbose_name="用戶", related_name='user',on_delete=models.CASCADE) fans=models.ForeignKey(UserProfile, verbose_name="粉絲", related_name='fans',on_delete=models.CASCADE) add_time = models.DateTimeField(default=datetime.now, verbose_name="添加時間") class Meta: verbose_name = "粉絲表" verbose_name_plural = verbose_name def __str__(self): return self.user class MakeMoney(models.Model): """佣金記錄表""" user = models.ForeignKey(UserProfile, verbose_name="用戶", related_name='u',on_delete=models.CASCADE) fans = models.ForeignKey(UserProfile, verbose_name="粉絲", related_name='f',help_text='從哪一個粉絲的消費中分紅的', on_delete=models.CASCADE) money=models.FloatField(default=0,verbose_name='佣金') add_time = models.DateTimeField(default=datetime.now, verbose_name="添加時間") class Meta: verbose_name = "佣金記錄表" verbose_name_plural = verbose_name def __str__(self): return self.user class GetCash(models.Model): """提現記錄表""" user = models.ForeignKey(UserProfile, verbose_name="用戶", on_delete=models.CASCADE) money = models.FloatField(default=0, verbose_name='提現金額') add_time = models.DateTimeField(default=datetime.now, verbose_name="添加時間") class Meta: verbose_name = "提現記錄表" verbose_name_plural = verbose_name def __str__(self): return self.user
2.執行數據更新命令:
python manage.py makemigrations
python manage.py migrate
3.其中「提現記錄表」是暫時的,等到後期若是微信的「企業提款到零錢」功能能夠開放使用,則要對這個表進行修改。