Iterate django apps and models

Django -- Posted on March 7, 2024

Iterate django apps and models

              
                from django.apps import apps
        app_list = []
        for app in apps.get_app_configs():
            d = {}
            d['app_label'] = app.label
            d['models'] = []
            for model in app.models:
                d['models'].append(model)
            app_list.append(d)
        print(app_list)
                  
   
            

Related Posts