码迷,mamicode.com
首页 > 其他好文 > 详细

Django-Content-type用法

时间:2018-09-02 00:09:25      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:types   for   normal   rbo   pes   object_id   name   table   imp   

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用法

标签:types   for   normal   rbo   pes   object_id   name   table   imp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!