Created
March 4, 2014 12:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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