This owes a debt to a number of earlier snippets by myself and others, including:
*(most directly)* [#2868](http://djangosnippets.org/snippets/2868/), plus [#2020](http://djangosnippets.org/snippets/2020/), [#2712](http://djangosnippets.org/snippets/2712/), [#1697](http://djangosnippets.org/snippets/1697/)
Use of OrderedDict means it requires Python 2.7+. You also need to `pip install singledispatch` which is a backport of a Python 3.4 feature.
Singledispatch (along with custom attributes instead of a factory function) gives a very clean interface in your ModelAdmin, whether or not you need a custom `short_description`.
This version allows you to (optionally) specify custom column labels, or to (optionally) use Django's usual prettifying mechanism (`field.verbose_name`).
Thanks to #2868 it can do relation-spanning double-underscore lookups and also model attribute/method (rather than field) lookups for columns, just like you can in your ModelAdmin `list_display`.
Ever tried to unit test custom fields or abstract models? If so, you probably used a solution like [this one](http://djangosnippets.org/snippets/2843/). It surely works, but it has some issues:
1. Runs 'syncdb' several times.
2. It's not automatic. You must add the mixin or copy the code to each of the TestCases.
This test runner adds to INSTALLED_APPS the 'app.tests' package for **each of the specified** apps, **before the 'syncdb' happens**.
This has the [discovery runner](https://pypi.python.org/pypi/django-discover-runner) as a dependency (for 1.5 only, it will be the default in 1.6). However, it comes as a mixin so it should be easily pluggable to other test runners.
If you intend to use the mixin with other runners, note that it imports 'app.tests.models' so it won't work with tests modules (tests.py). Your runner must "use" test packages (like discovery runner).
# USAGE
# in your settings.py:
TESTAPPS_INSTALL = (
'app1',
'app2',
# ...
)
TEST_RUNNER = 'testapp_runner.DiscoverTestAppRunner' # example import path
# extra apps in command line.
# run test for apps 'app1' to 'app4', adding 'app3' and 'app4' to the TESTAPPS_INSTALL setting.
manage.py test app1 app2 app3 app4 --with-test-app=app3 --with-test-app=app4
- django
- testing
- apps
- testrunner
- test-runner
- app-models