Snippet List
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
This allows you to order the models on the index page of the administration site in a custom way.
This modification goes in the index method of django.contrib.admin.sites.AdminSite. I personally monkey patched it in where my models are loaded and registered with the admin site. Be careful that if you add new models you update the sorting dictionary, else you will get a key error. If no sorting is defined for an app, it will default to alphabetical order.
Note that you'll probably want to also insert this into the app_index function as well.
---
If you like my work, please check out my employer's site at 829llc.com
- Dan
- models
- admin
- sort
- sorting
- app-models
I never found a good snippet or tutorial to get the app_list (in django.admin) on other pages except the index page. So i started asking on irc j00bar has given me a very nice answer, but first i didn't know what to do with it till now.
Anyways this snippet is very handy for the people who wants this but don't know how to get it.
This is special made for the django version 1.1
Installation is quite easy, it is a context processor, so download this file put anywhere in your project, i got it in a app called cms_theme (theme and template related stuff.) and put the location in your settings.py file, example:
`TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.request',
'****cms.cms_themes.context_processors.theme',
'****cms.cms_themes.context_processors.applist',
)`
The '****' stuff is nothing, i replaced my company name with it.
Of course you may put the context processor anywhere else, that is your choice.
Good luck!
Alexander
- django
- models
- admin
- python
- applications
- app_list
- app-models
3 snippets posted so far.