Created
March 4, 2011 11:29
-
-
Save mdales/854488 to your computer and use it in GitHub Desktop.
LAzy django assistant
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
import readline, rlcompleter | |
readline.parse_and_bind ("bind ^I rl_complete") | |
globals().update({"test": 123}) | |
test2 = 123 | |
try: | |
from django.conf import settings | |
except ImportError: | |
pass | |
else: | |
app_list = settings.INSTALLED_APPS | |
for app in app_list: | |
models_module = app + ".models" | |
try: | |
module = __import__(models_module) | |
except ImportError: | |
pass | |
else: | |
pathparts = models_module.split('.')[1:] | |
for path in pathparts: | |
module = module.__dict__[path] | |
namespace = vars(module) | |
all_names = namespace.get("__all__") | |
if all_names is None: | |
all_names = [key for key in namespace if key[0] != "_"] | |
my_namespace = {} | |
for name in all_names: | |
print "adding %s" % name | |
my_namespace[name] = namespace[name] | |
globals().update(my_namespace) | |
print "Imported %s" % models_module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment