在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.重建用户表:1.在settings中配置: AUTH_USER_MODEL='users.UserProfile' 2.apps/users/models.py中建立UserProfile表: 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 3.执行数据更新命令: python manage.py makemigrations
python manage.py migrate
2.建立地区表: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
3.建立用户增加积分表1.在apps/users/models.py中建立 用户增加积分表: 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
2.ad的数据表设计:1.安装处理图片的依赖包pillow: pip install pillow 2.在apps/ad/models.py中: from django.db import models
3.执行数据更新命令: python manage.py makemigrations
python manage.py migrate
3.trade数据表设计: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
4.user_operation数据表设计: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.其中“提现记录表”是暂时的,等到后期如果微信的“企业提款到零钱”功能可以开放使用,则要对这个表进行修改。
|
请发表评论