Skip to content

Instantly share code, notes, and snippets.

@mdales
Created March 4, 2011 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdales/854488 to your computer and use it in GitHub Desktop.
Save mdales/854488 to your computer and use it in GitHub Desktop.
LAzy django assistant
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