from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey,GenericRelation
from django.contrib.contenttypes.models import ContentType
# Create your models here. from django.db import models
__all__ =["User","Usertoken","Course","CourseDetail","Chapter","CourseSection","OftenAskedQuestion","PricePolicy"] ##认证模型
class User(models.Model):
user=models.CharField(max_length=)
pwd =models.CharField(max_length=) class Usertoken(models.Model):
user =models.OneToOneField("User")
token=models.CharField(max_length=) #.课程表
class Course(models.Model):
"""
课程表
"""
title =models.CharField(verbose_name="课程名称",max_length=)
course_img =models.CharField(verbose_name="课程图片",max_length=)
level_choices=(
(,"初级"),
(,"中级"),
(,"高级"),
)
level =models.IntegerField(verbose_name="课程难易程度",choices=level_choices,default=) #用GenericForeignKey反向查询,不会生成表字段,切勿删除.
price_policy =GenericRelation("PricePolicy")
asked_question =GenericRelation("OftenAskedQuestion")
def __str__(self):
return self.title #.课程详情表
class CourseDetail(models.Model):
"""
课程详情
"""
course =models.OneToOneField(to="Course")
slogon=models.CharField(verbose_name="口号",max_length=)
recommend_courses =models.ManyToManyField(verbose_name="推荐课程",to="Course",related_name="rc",null=True,blank=True) def __str__(self):
return "课程详情:"+self.course.title #.章节表
class Chapter(models.Model):
"""
章节
"""
num= models.IntegerField(verbose_name="章节")
name= models.CharField(verbose_name="章节名称",max_length=)
course =models.ForeignKey(verbose_name="所属课程",to= "Course") def __str__(self):
return self.name #.课时表
class CourseSection(models.Model):
"""
课时目录
"""
chapter =models.ForeignKey("Chapter",related_name="course_sections")
name =models.CharField(max_length=) class Meta:
verbose_name_plural="11.课时" #.常见问题表.#用到content-type
class OftenAskedQuestion(models.Model):
"""
常见问题
"""
content_type =models.ForeignKey(ContentType,
limit_choices_to={"model__contains":"course"}) #关联 course or degree_course
object_id =models.PositiveIntegerField()
content_object =GenericForeignKey("content_type","object_id") question =models.CharField(max_length=)
answer =models.TextField(max_length=) def __str__(self):
return "%s-%s"%(self.content_object,self.question) class Meta:
unique_together=("content_type","object_id","question")
verbose_name_plural="08.常见问题" #.价格课程表.#用到content-type
class PricePolicy(models.Model):
"""
价格与课程的有效期表
"""
content_type =models.ForeignKey(ContentType) #关联 course or degree_course
object_id =models.PositiveIntegerField()
content_object =GenericForeignKey("content_type","object_id") valid_period_choices= ((,"1天"),(,"3天"),
(,"1周"),(,"2周"),
(,"1个月"),
(,"2个月"),
(,"3个月"),
(,"6个月"),(,"12个月"),
(,"18个月"),(,"24个月"),
) valid_period =models.SmallIntegerField(choices=valid_period_choices)
price =models.FloatField() def __str__(self):
return str(self.content_object)+ "====>"+str(self.price) #优惠券表
class Coupon(models.Model):
"优惠券生成规则 "
name =models.CharField(max_length=,verbose_name="活动名称")
brief = models.TextField(blank=True,null=True,verbose_name="优惠券介绍")
coupon_type_choice =((,"立减劵"),(,"满减券"),(,"折扣卷"))
coupon_type =models.SmallIntegerField(choices=coupon_type_choice,default=,verbose_name="券类型") """
通用:
money_equivalent_value=
off_percent =null
minimum_consume = 满减:
money_equivalent_value =
off_percent=null
minimum_consume =
折扣:
money_equivalent_value =
off_percent =
minimum_consume =
"""
money_equivalent_value =models.IntegerField(verbose_name="等值货币",blank=True,null=True)
off_percent= models.PositiveIntegerField("折扣百分比",help_text="只针对折扣卷,例7.9,写成79",blank=True,null=True)
minimum_consume =models.PositiveIntegerField("最低消费",default=,help_text="仅在满减卷时填写此字段") content_type =models.ForeignKey(ContentType,blank=True,null=True)
object_id =models.PositiveIntegerField("绑定课程",blank=True,null=True,help_text="可以把优惠券和课程绑定")
content_object =GenericForeignKey("content_type","object_id") quantity =models.PositiveIntegerField("数量(张)",default=)
open_date = models.DateField("优惠券领取开始时间")
close_date =models.DateField("优惠券结束时间")
valid_begin_date =models.DateField(verbose_name="有效期开始时间",blank= True,null=True)
valid_end_date =models.PositiveIntegerField(verbose_name="有效期结束时间",blank=True,null=True)
coupon_valid_days= models.PositiveIntegerField(verbose_name="优惠券有效期(天)",blank=True,null=True,
help_text="自优惠券被领开始算起")
date =models.DateTimeField(auto_now_add=True) class Meta:
verbose_name_plural="31.优惠券生成记录" def __str__(self):
return "%s(%s)"%(self.get_coupon_type_display(),self.name) def save(self,*args,**kwargs):
if not self.coupon_valid_days or (self.valid_begin_date and self.valid_end_date):
if self.valid_begin_date and self.valid_end_date:
raise ValueError("valid_end_date 有效期结束日期必须晚于 valid_begin_date")
if self.coupon_valid_days ==:
raise ValueError("coupon_valid_days 有效期不能为0")
if self.coupon_valid_days ==:
raise ValueError("coupon_valid_days 有效期不能为0 ")
if self.close_date <self.open_date:
raise ValueError("close_date 优惠券领取结束时间必须晚于open_date优惠券领取开始时间")
super(Coupon, self).save(*args,**kwargs) class CouponRecord(models.Model):
"""优惠券发放,消费记录"""
coupon =models.ForeignKey("Coupon")
number =models.CharField(max_length=,unique=True)
user =models.ForeignKey("User",verbose_name="拥有者")
status_choices =((,"未使用"),(,"已使用"),(,"已过期"))
status= models.SmallIntegerField(choices=status_choices,default=)
get_time =models.DateTimeField(verbose_name="领取时间",help_text="用户领取时间")
used_time =models.DateTimeField(blank=True,null=True,verbose_name="使用时间") class Meta:
verbose_name_plural ="32.用户优惠券" def __str__(self):
return "%s-%s-%s"%(self.user,self.number,self.status)

day 109结算中心.的更多相关文章

  1. python 全栈开发,Day103(微信消息推送,结算中心业务流程)

    昨日内容回顾 第一部分:考试题(Python基础) 第二部分:路飞相关 1. 是否遇到bug?难解决的技术点?印象深刻的事? - orm操作费劲 - 最开始学习路由系统时候,匹配规则: 答案一: 有, ...

  2. AI学习吧-结算中心

    结算中心流程 在结算中心中,主要是对用户添加到购物车商品的结算,由于用户可能添加了多个课程,但是,结算时会选择性的进行支付.在结算时会选中课程id,和对应的价格策略.在后台,首先会对用户进行校验,验证 ...

  3. qhfl-7 结算中心

    结算中心,即从购物车前往支付前的确认页面,这里要开始选择优惠券了 """ 前端传过来数据 course_list 课程列表 redis 中将要存放的结算数据 { sett ...

  4. python 全栈开发,Day106(结算中心(详细),立即支付)

    昨日内容回顾 1. 为什么要开发路飞学城? 提供在线教育的学成率: 特色: 学,看视频,单独录制增加趣味性. 练,练习题 改,改学生代码 管,管理 测,阶段考核 线下:8次留级考试 2. 组织架构 - ...

  5. python 全栈开发,Day104(DRF用户认证,结算中心,django-redis)

    考试第二部分:MySQL数据库 6.  MySQL中char和varchar的区别(1分) char是定长,varchar是变长. char的查询速度比varchar要快. 7.   MySQL中va ...

  6. Django day 38 结算中心,支付中心,计算价格方法

    一:结算中心 二:支付中心 三:计算价格方法

  7. PP.io的三个阶段,“强中心”——“弱中心”——“去中心”

    什么是PP.io? PP.io是我和Bill发起的存储项目,目的在于为开发者提供一个去中心化的存储和分发平台,能做到更便宜,更高速,更隐私. 当然做去中心化存储的项目也有好几个,FileCoin,Si ...

  8. python 全栈开发,Day105(路飞其他数据库表结构,立即结算需求)

    考试第三部分:Django 16.  列列举你熟悉的Http协议头以及作用.(1分) Accept-Charset: 用于告诉浏览器,客户机采用的编码 Host: 客户机通过这个头告诉服务器,想访问的 ...

  9. s11 day103 luffy项目结算部分+认证+django-redis

    1.增加认证用的表 class Account(models.Model): username =models.CharField(,unique=True) email= models.EmailF ...

随机推荐

  1. PHP json_encode 中文不转码,低版本处理

    5.4 以上版本可以使用 JSON_UNESCAPED_UNICODE  来解决,但是低版本的,需要用其他方式 需要注意的是,encode_json参数为数组,不能为对象 function encod ...

  2. POJ 1438 One-way Traffic (混合图+边双连通)

    <题目链接> 题目大意: 给定一个混合图,问你在能够使得图中所有点能够两两到达的情况下,尽可能多的将无向边变成有向边,输出这些无向边的变化方案. 解题分析:这与之前做过的这道题非常类似 P ...

  3. APM-全链路追踪

    1.故障快速定位 跨语言实现开发中在业务日志中添加调用链ID,可以通过调用链结合业务日志快速定位错误信息. 2.各个调用环节的性能分析 分析调用链的各个环节耗时,分析系统的性能瓶颈,找到系统的薄弱环节 ...

  4. ADC(简易的DMA传输)的认识

    ADC(简易的DMA传输)的认识 首先看到是ADC的特性 1.ADC的12位分辨率.不能直接测量负电压,然后是最小量程化单位是LSB=Vref+/212 2.单次和转换模式的使用 3. 从通道0到通道 ...

  5. 20180119-01-RACSignal的基础

    一.获取一个信号的方式 1.单元信号 RACSignal *signal1 = [RACSignal return:@"Some Value"]; RACSignal *signa ...

  6. ubuntu vim8.1编译安装

    sudo apt-get install libncurses5-dev python-dev python3-dev libgtk-3-dev libatk1.0-dev libbonoboui2- ...

  7. repquota - 文件系统配额的汇总

    SYNOPSIS(总览) repquota [ -vugs ] filesystem... repquota [ -avugs ] DESCRIPTION(描述) repquota 显示与配额文件相关 ...

  8. C语言获取当前时间

    #include <stdio.h> #include <time.h> void main () { time_t rawtime; struct tm * timeinfo ...

  9. (ACM模板)队列queue

    #include<iostream> #include<cstdio> #include<queue> using namespace std; struct po ...

  10. 字符串函数-unquote()函数

    字符串函数顾名思意是用来处理字符串的函数.Sass 的字符串函数主要包括两个函数: unquote($string):删除字符串中的引号: quote($string):给字符串添加引号. 1.unq ...