Django的ContentType框架django_conent_type

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

五、

猜你喜欢

转载自www.cnblogs.com/weihengblog/p/9271319.html