2013-12-17 14 views

答えて

6

ContentTypeは、データベース内のモデルとテーブルで、djangoアプリケーションの他のすべてのテーブル/モデルに関する情報が含まれています。

のPostgresテーブル:postgresの中

=> \d django_content_type; 

    Column |   Type   |       Modifiers 
-----------+------------------------+----------------------------------------- 
id  | integer    | not null ... 
name  | character varying(100) | not null 
app_label | character varying(100) | not null 
model  | character varying(100) | not null 

データ:たとえば

=> SELECT * from django_content_type; 

id |   name   |  app_label  |  model   
----+-----------------------+-------------------+--------------------- 
    1 | permission   | auth    | permission 
    2 | group     | auth    | group 
    3 | user     | auth    | user 
    4 | auth user groups  | auth    | authusergroups 
... 

、アプリケーションでカスタム管理を構築するために、そしてテーブルのリストを取得したい場合は、ContentTypeを使用することができますモデル:

>>> from django.contrib.contenttypes.models import ContentType 
>>> tables = ContentType.objects.filter(app_label="my_app") 

使用するdjangoの管理者、コンテンツタイプactiそこに使われている。

関連する問題