servermon/servermon — pull request #52 by rowanthorpe (2014-04-07 19:33:35+00:00)
Title: Move admin.site.register(Key) to hwdoc where file is included

This is to avoid the problem of the file being included more than once but not by the *exact same* call, causing the admin.site.register(Key) to be run more than once, causing error. `servermon/keyvalue/admin.py` is included from `servermon/hwdoc/admin.py` and again (obviously in a subtly different form) by admin-autodiscovery

This commit moves the registration to hwdoc/admin.py as that seems to be the only place the keyvalue admin is used anyway, and this is the least invasive "fix".

*NB:*
This problem is similar to [this question at stackoverflow](http://stackoverflow.com/questions/10986284/already-registered-at-admin-django-1-2-error) and another perhaps more future-proof "fix" could be like [this django snippet](https://djangosnippets.org/snippets/2066/) or [this stackoverflow answer](http://stackoverflow.com/a/9444280) (and see the [this comment on that answer](http://stackoverflow.com/questions/9443863/register-every-table-class-from-an-app-in-the-django-admin-page/9444280#comment28882546_9444280) for a more precise tweak). Or if you want to go down the road of proxy models you could do something like [this answer at stackoverflow](http://stackoverflow.com/a/2228821).

For reference, the error I was getting (and which is silenced by this commit) is:

```
AlreadyRegistered at /
The model Key is already registered
Request Method: GET
Request URL: http://[blah]:8000/
Django Version: 1.4.5
Exception Type: AlreadyRegistered
Exception Value:
The model Key is already registered
Exception Location: /usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py in register, line 80
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/srv/servermon/servermon-68293100fb95e7f1c173259162801a22f75a3e00/servermon',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/pymodules/python2.7']
```