當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Django ContentTypeManager用法及代碼示例

本文介紹django.contrib.contenttypes.models.ContentTypeManager的用法。

聲明

class ContentTypeManager

ContentType 還有一個自定義管理器 ContentTypeManager ,它添加了以下方法:

當您知道需要使用 ContentType 但又不想費心獲取模型的元數據以執行手動查找時, get_for_model() 方法特別有用:

>>> from django.contrib.auth.models import User
>>> ContentType.objects.get_for_model(User)
<ContentType: user>

相關用法


注:本文由純淨天空篩選整理自djangoproject.com大神的英文原創作品 django.contrib.contenttypes.models.ContentTypeManager。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。