Django : How can I find a list of models that the ORM knows?

前端 未结 7 1738
挽巷
挽巷 2020-12-04 08:48

In Django, is there a place I can get a list of or look up the models that the ORM knows about?

7条回答
  •  没有蜡笔的小新
    2020-12-04 09:22

    List models using http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/

    from django.contrib.contenttypes.models import ContentType
    
    for ct in ContentType.objects.all():
        m = ct.model_class()
        print "%s.%s\t%d" % (m.__module__, m.__name__, m._default_manager.count())
    

提交回复
热议问题