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

前端 未结 7 1708
挽巷
挽巷 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:27

    If you want a dictionary with all models you can use:

    from django.apps import apps
    
    models = {
        model.__name__: model for model in apps.get_models()
    }
    

提交回复
热议问题