1

I am creating django permissions based on django views rather than basic model based permissions. Hence I want to get the list of all the classes in a view. I tried the following:

from django.apps import apps
apps.get_app_config('my_app')

And also:

import sys, inspect
inspect.getmembers(sys.modules['my_app'], inspect.isclass)

But I didn't get classes object.

halfer
  • 19,824
  • 17
  • 99
  • 186
Manasvi Batra
  • 384
  • 2
  • 14

1 Answers1

0
apps.get_app_config('my_app').get_models() 

will return a list of all models declared in your application.

if you want to get all models including those in INSTALLED_APPS you can

appconfigs=apps.get_app_configs()
for appconfig in appconfigs:
    models = appconfig.get_models()
Steig
  • 173
  • 2
  • 5