【1125 | Day65】content_type介绍(在表设计优化中十分重要)

一、content_type介绍

将Django中所有模块里的所有表进行编号并存储到content_type表中,content_type表内存在两个字段的映射关系。

二、content_type应用

  1. 应用一:权限表的权限是操作表的,所有在权限表中有一个content_type表的外键,标识该权限具体操作的是哪张表
  2. 应用二:价格策略

三、content_type演示


"""
Course:
name、type、days、price、vip_type
基础	免费课  7		0
中级	学位课	 180	69
究极	会员课	 360    	 至尊会员


Course:
name、type、days、content_type_id
基础	免费课  7	  null
中级	学位课	 180   1
究极	会员课	 360   2

app01_course_1
id、price

app01_course_2
id vip_type

content_type表(Django提供)
id、app_label、model
1	app01	 course_1
2	app01	 course_2
"""
原文地址:https://www.cnblogs.com/fxyadela/p/11930254.html