django/django — pull request #303 by phill-tornroth (2012-08-25 12:06:03+00:00)
Title: Auto-import support for models and other objects in shell

Good morning!

This change adds the ability to setup pre-importing of models or other usefuls in the Django admin shell. I think it's something loads of folks would enjoy, and adding it yourself is actually kind of a pain since as far as I can tell it involves copy-pasting the entire shell.py contents. The core change adds support for listing thing you'd like to auto-import in `settings`, as well as defining a method in the shell command that's easily override-able if folks want to do even nuttier stuff.

I figured I'd start with a pull request instead of an email discussion to keep things concrete. First, here's how I'm proposing this would work:

(settings.py)
```python
SHELL_IMPORTS_ALL_MODELS = True
SHELL_IMPORTS = [
'django.db.models.Q',
'haystack.query.SearchQuerySet'
]
```

Defaults are to import nothing, existing projects ought to be unaffected. The above would do what you'd imagine it doing. Each of the application's models, `Q`, and `SearchQuerySet` would all be imported and auto-completable.

Super notably, this pull request isn't complete. I mean it as a starting point for getting general consensus before moving forward. Things (that I know of) that deserve addressing:

* Unit tests (happy to write them, but don't want to unless there's a general sense that the change has promise)
* Docs (same)
* What to do (if anything) with collisions. For instance if `SHELL_IMPORTS_ALL_MODELS=True` and more than one app has a model with the same name. I'm imagining logging a warning but haven't built that support yet.

Anyways, hope it's not crazy or over-discussed already. Thanks in advance for the consideration!