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

Django的ContentType框架django_conent_type

时间:2018-07-06 01:48:46      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:har   use   The   unique   obj   elf   pre   font   class   

Django包含了一个conenttype应用程序,记录了Django项目中安装的所有模型,为当前项目所有基于Django驱动的model提供了更高层次的抽象接口。

一、概述

ContentTypes应用程序的核心是 django.contrib.contenttypes.models.ContentType:

@python_2_unicode_compatible
class ContentType(models.Model):
    app_label = models.CharField(max_length=100)
    model = models.CharField(_(python model class name), max_length=100)
    objects = ContentTypeManager()

    class Meta:
        verbose_name = _(content type)
        verbose_name_plural = _(content types)
        db_table = django_content_type
        unique_together = ((app_label, model),)

    def __str__(self):
        return self.name

当我们不创建任何model的情况下就迁移数据库,就会发现在数据表中有名为django_content_type的表

1|admin|logentry
2|auth|group
3|auth|user
4|auth|permission
5|contenttypes|contenttype
6|sessions|session

 

 

 

 

二、安装ContentTypes框架

三、ContentType模型

四、ContentType方法

五、

 

Django的ContentType框架django_conent_type

标签:har   use   The   unique   obj   elf   pre   font   class   

原文地址:https://www.cnblogs.com/weihengblog/p/9271319.html

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