On Fri, Mar 26, 2010 at 4:47 PM, Phlip <[email protected]> wrote:
> I am in anguish over watching my colleagues fire up python manage.py
> shell...
>
> ...and then typing several incredibly long import lines before
> actually getting anything done.
>
> These same colleagues also seem to have itchy ^C fingers, meaning they
> bail out of the shell too often, too.
>
> How can we fix the first problem? How can this (otherwise useful)
> shell use a minimal or invisible import rubric, to grab, say, a bunch
> of models so they are all ready & available for use?
I use something like this (assuming you have iPython installed):
**********
#!/usr/bin/env ipython -i -nobanner
# don't need this part if DJANGO_SETTINGS_MODULE is already set in
your environment
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'YOUR.SETTINGS.MODULE'
from django.db.models import Count, Max, Min, Q
from django.db.models.loading import cache as appcache
local_dict = locals()
for model_class in appcache.get_models():
local_dict[model_class.__name__] = model_class
del local_dict, appcache, os
**********
Save that to a file in your PATH, make it executable, and you should be set.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.