class ContentType
Each instance of ContentType has two fields which, taken together, uniquely describe an installed model:
-
app_label -
The name of the application the model is part of. This is taken from the
app_labelattribute of the model, and includes only the last part of the application’s Python import path; “django.contrib.contenttypes”, for example, becomes anapp_labelof “contenttypes”.
-
model -
The name of the model class.
Additionally, the following property is available:
-
name -
The human-readable name of the content type. This is taken from the
verbose_nameattribute of the model.
Let’s look at an example to see how this works. If you already have the contenttypes application installed, and then add the sites application to your INSTALLED_APPS setting and run manage.py migrate to install it, the model django.contrib.sites.models.Site will be installed into your database. Along with it a new instance of ContentType will be created with the following values:
-
app_labelwill be set to'sites'(the last part of the Python path “django.contrib.sites”). -
modelwill be set to'site'.
Please login to continue.