最初のHTTPGET中(デーモンモードのWSGIがリロードされた直後)、admin.site.unregisterはNotRegistered例外をスローしますが、admin.site.registerはAlreadyRegistered例外(catch-22?)をスローします。ただし、後続のHTTPGETでは、すべてがエラーなしで問題なくロードされます。
設定:
- Django 1.3
- Apache 2.2
- CentOS
settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
#'django.contrib.sites', #(this didn't seem to make a difference)
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'base',
'sample',
'reports',
'south',
)
models.py:
from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
class Company(models.Model):
name = models.CharField(max_length=256)
class CompanyUser(models.Model):
company = models.ForeignKey(Company)
user = models.OneToOneField(User)
class CompanyUserInline(admin.StackedInline):
model = CompanyUser
max_num = 1
can_delete = False
class CompanyUserAdmin(AuthUserAdmin):
inlines = [ CompanyUserInline ]
# STUCK HERE !!
try:
admin.site.unregister(User)
# throws NotRegistered at / The model User is not registered
except:
admin.site.register(User, CompanyUserAdmin)
# throws AlreadyRegistered at / The model User is already registered