首页 > 其他 > 详细

Django-Content-type用法

时间:2018-09-01 23:03:42      阅读:224      评论:0      收藏:0      [点我收藏+]
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericRelation,GenericForeignKey

class  SuperCourse(models.Model):
    name = models.CharField(max_length=32,verbose_name="超级课名")
    course_policy = GenericRelation(‘CoursePolicy‘)

class NormalCourse(models.Model):
    name = models.CharField(max_length=32,verbose_name=‘普通课名‘)
    course_policy = GenericRelation(‘CoursePolicy‘)

class CoursePolicy(models.Model):
    price = models.IntegerField(verbose_name="价格")
    period = models.IntegerField(verbose_name="周期")
    object_id = models.IntegerField(verbose_name="课程id")
    table_name = models.ForeignKey(ContentType,verbose_name="关键在ContentType表里面的表名")
    # obj = GenericForeignKey(‘table_name‘,"object_id")
    obj = GenericForeignKey(ct_field=table_name,fk_field=object_id)
     

  

Django-Content-type用法

原文:https://www.cnblogs.com/leigepython/p/9571583.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!