1.models

class PricePolicy(models.Model):
"""价格与有课程效期表"""
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id') valid_period_choices = ((1, '1天'), (3, '3天'),
(7, '1周'), (14, '2周'),
(30, '1个月'),
(60, '2个月'),
(90, '3个月'),
(180, '6个月'), (210, '12个月'),
(540, '18个月'), (720, '24个月'),
)
valid_period = models.SmallIntegerField(choices=valid_period_choices)
price = models.FloatField() class Meta:
unique_together = ("content_type", 'object_id', "valid_period") def __str__(self):
return "%s(%s)%s" % (self.content_object, self.get_valid_period_display(), self.price)
class Meta:
verbose_name = "价格与有课程效期表"
verbose_name_plural = "价格与有课程效期表"
class DegreeCourse(models.Model):
"""学位课程"""
name = models.CharField(max_length=128, unique=True)
course_img = models.CharField(max_length=255, verbose_name="缩略图")
brief = models.TextField(verbose_name="学位课程简介", )
total_scholarship = models.PositiveIntegerField(verbose_name="总奖学金(贝里)", default=40000)
mentor_compensation_bonus = models.PositiveIntegerField(verbose_name="本课程的导师辅导费用(贝里)", default=15000)
# 忽略,用于GenericForeignKey反向查询, 不会生成表字段,切勿删除
coupon = GenericRelation("Coupon") # 为了计算学位奖学金
period = models.PositiveIntegerField(verbose_name="建议学习周期(days)", default=150)
prerequisite = models.TextField(verbose_name="课程先修要求", max_length=1024)
teachers = models.ManyToManyField("Teacher", verbose_name="课程讲师") # 忽略,用于GenericForeignKey反向查询,不会生成表字段,切勿删除
degreecourse_price_policy = GenericRelation("PricePolicy") def __str__(self):
return self.name
class Meta:
verbose_name = "学位课程"
ve
rbose_name_plural = "学位课程"

2.views

正向查找:models对象.content_object得到的是models对象

反向查找:models对象.反向关联字段.all()得到的是QuerySet对象

添加:content_type+_id其他不变

from django.shortcuts import render,HttpResponse

# Create your views here.

from app01 import models

def index(request):
'''查看价格与有课程效期表'''
DegreeCourse_obj=models.PricePolicy.objects.get(id=1).content_object
'''通过content_object直接找到与其关联的models对象'''
print('aaaaa',DegreeCourse_obj,type(DegreeCourse_obj))
'''反向关联查找'''
b = models.DegreeCourse.objects.get(id=1).degreecourse_price_policy.all()
print('bbbb',b)
'''ADD'''
models.PricePolicy.objects.create(content_type_id=1,object_id=1,valid_period=60,price=6666)
return HttpResponse('ok!!!')

Django content-type 使用的更多相关文章

  1. Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...

  2. Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...

  3. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...

  4. SharePoint自动化系列——Content Type相关timer jobs一键执行

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...

  5. 转载 SharePoint【Site Definition 系列】– 创建Content Type

    转载原地址:  http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...

  6. the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header

    the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header ...

  7. Springs Element 'beans' cannot have character [children], because the type's content type is element-only

    Springs Element 'beans' cannot have character [children], because the type's content type is element ...

  8. springboot 报错 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

    开始 controller 方法写的是 @RequestMapping( value = "/add", method = RequestMethod.POST ) public ...

  9. .NET获取文件的MIME类型(Content Type)

    第一种:这种获取MIME类型(Content Type)的方法需要在.NET 4.5之后才能够支持,但是非常简单. 优点:方便快捷 缺点:只能在.NET 4.5之后使用 public FileResu ...

  10. 万能的ctrl+shift+F(Element 'beans' cannot have character [children], because the type's content type is element-only.错误)

    今天在spring-servlet.xml文件中出现了一个莫名其妙的错误:Element 'beans' cannot have character [children], because the t ...

随机推荐

  1. maven依赖查找方法

    http://mvnrepository.com 1. 搜索依赖库         2. 选择合适版本 3. 复制配置 点击合适的版本进入,负责maven配置: <dependency> ...

  2. 集腋成裘-02-css基础-01

    CSS 层叠样式表(Cascading Style Sheets)(级联样式表) 1 选择器 1.1 写法 选择器是一个选择标签的过程. 选择器{属性:值;...} 1.2 基础选择器 标签选择器 类 ...

  3. 步步为营101-同一个PCode下重复的OrderNumber重新排序

    USE [K2_WorkFlow_Test] GO /****** Object: StoredProcedure [dbo].[sp_UpdateBPM_DictionaryForOrderNumb ...

  4. 迅速上手:使用taro构建微信小程序基础教程

    前言 由于微信小程序在开发上不能安装npm依赖,和开发流程上也饱受诟病:Taro 是由京东·凹凸实验室(aotu.io)倾力打造的 多端开发解决方案,它的api基于react,在本篇文章中主要介绍了使 ...

  5. context日志

    class Program { static void Main(string[] args) { List<wolf_example> Listw; using (var ctx = n ...

  6. Spring boot+CXF开发WebService Demo

    最近工作中需要用到webservice,而且结合spring boot进行开发,参照了一些网上的资料,配置过程中出现的了一些问题,于是写了这篇博客,记录一下我这次spring boot+cxf开发的w ...

  7. [转]MySQL 数据类型(float)的注意事项

    http://www.cnblogs.com/zhoujinyi/archive/2013/04/26/3043160.html 可能由于版本关系,我的mysql5.7插入数据超过范围时会提示,126 ...

  8. awk常见用法

    awk作为linux字符搜索,结果统计的实用工具,其在linux日常运维中有着很多的巧妙运用.下面就来技术一下刚刚学到的技巧 #awk命令统计文件夹下所有文件大小 ls -l |awk 'BEGIN ...

  9. 正则表达式匹配URL或者网址

    正则表达式 (http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])? ...

  10. python全栈开发day53-mysql

    mysql的使用 (1)下载 解压到指定的目录. (2)取到C:\mysql-5.7.22-winx64\mysql-5.7.22-winx64\bin路径 添加到系统的环境变量中,后面一定要加分号. ...