Itterate apps

Django -- Posted on Dec. 29, 2017

Itterate apps

              
                from django.apps import apps
from django.conf import settings

def get_apps(request):
    apps_list = {}
    for app in settings.INSTALLED_APPS:
        if 'django' in app:
            pass
        else:
            app_models = apps.get_app_config(app).get_models()
            apps_list[app] = [model for model in app_models]
            if len(apps_list[app]) == 0:
                del apps_list[app]

    return {
        'apps': apps_list
    }
                  
   
            

Related Posts