﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6776	"Importing a model from one app into another app causes ""AlreadyRegistered"" exception."	Manuel <manny@…>	Brian Rosner	"example:

in a project with two apps, app1 and app2, with the following models.py files:

app1/models.py:
{{{
from django.db import models
from django.contrib import admin

class MyFirstModel(models.Model):
    pass

admin.site.register(MyFirstModel)

...
}}}

app2/models.py
{{{
from django.db import models
from django.contrib import admin
from app1.models import MyFirstModel

...
}}}
running the command:

{{{
./manage.py runserver
}}}

raises the following exception:
{{{
Unhandled exception in thread started by <function inner_run at 0x2ab13a637c80>
Traceback (most recent call last):
...
 File ""/usr/local/lib/python2.4/site-packages/django/contrib/admin/sites.py"", line 82, in register
    raise AlreadyRegistered('The model %s is already registered' % model.__name__)
django.contrib.admin.sites.AlreadyRegistered: The model MyFirstModel is already registered

}}}

My quick and dirty solution is to get rid of the exception in the ''register'' method of the ''!AdminSite'' class in the ''sites.py'' file.  i.e. changing it from this:

{{{
for model in model_or_iterable:
     if model in self._registry:
        raise AlreadyRegistered('The model %s is already registered' % model.__name__)
     self._registry[model] = admin_class(model, self)
}}}

to this:

{{{
for model in model_or_iterable:
    if not model in self._registry:
        self._registry[model] = admin_class(model, self)
}}}

In this way models are only registered if they haven't already been registered, and are ignored otherwise (instead of raising an exception) - as far as I can tell this shouldn't be a problem - but I'm not familiar enough with the code and your objectives to know for sure.  

"	Uncategorized	closed	Uncategorized	newforms-admin	Normal	fixed	nfa-blocker	cmawebsite@…	Accepted	1	0	0	0	0	0
