I am experiencing this error in the Django 1.2 admin.
Scenario:
I have two applications, for example app1 and app2 inside my project. In both of these applications, I defined their respective admin.py files to connect each of them to the corresponding django admin sites.
Inside app1 admin.py, I defined three ModelAdmin classes corresponding to the three model classes in app 1, and registered two of them on the admin site.
class App11stModelAdmin (admin.ModelAdmin):
Inside app2 I imported app1.App11stModelAdmin to define the admin model of the app2 model.
inside admin.py app2 :
from app1.admin import App11stModelAdmin class App21stModelAdmin(App11stModelAdmin):
Using this code, I get the following error message:
AlreadyRegistered at /admin/ The model App12ndModel is already registered Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Django Version: 1.2 Exception Type: AlreadyRegistered Exception Value: The model App12ndModel is already registered
This is strange because I'm sure I only register the model administrator once. When I commented out the register instruction for this model, I got the same error, but now for the App13rdModel model.
In the meantime, to fix this problem, I deleted the registration statements and instead placed them inside the βstaticβ function inside app1 admin.py.
like: inside app1 admin.py
def register(): admin.site.register(App12ndModel, App12ndModelAdmin) admin.site.register(App13rdModel, App13rdModelAdmin)
and then in app2 admin.py
I have included the register function in import:
from app1.model import App11stModelAdmin, register ...... ......
And it works. I no longer get an already registered error.
Question:
What did I do that led to this error? I am new to Django and Python.
Many thanks!