Skip to content

Instantly share code, notes, and snippets.

@asfaltboy
Created March 4, 2014 12:48
Show Gist options
  • Save asfaltboy/9345869 to your computer and use it in GitHub Desktop.
Save asfaltboy/9345869 to your computer and use it in GitHub Desktop.
get all app.Model in a Django project, excluding some models as required
from django.db import models
app_names = []
excuded = ['SomeModel', ...]
for app in models.get_apps():
for model_class in models.get_models(app):
if model_class.__name__ in :
continue
app_label = app.__name__.replace('.models', '').split('.')[-1]
app_names.append(u'%s.%s' % (app_label, model_class.__name__))
" ".join(app_names)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment