2013-12-17 14 views

risposta

6

ContentType è solo il modello e la tabella nel database che contengono informazioni su tutte le altre tabelle/modelli nella tua applicazione django. tavolo

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 

dati in Postgres:

=> 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 
... 

Per esempio, se si vuole costruire un amministratore personalizzato nell'applicazione, e ottenere l'elenco delle tabelle è possibile utilizzare ContentType modello:

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

Controllare le origini di amministrazione django per gli utenti, ContentTypes acti vely usato lì.

Problemi correlati