Ticket #8245: Misleading-AlreadyRegistered-00.diff

File Misleading-AlreadyRegistered-00.diff, 915 bytes (added by , 16 years ago)

Fixes the bug by unregistering models that were registered in the admin.py file before the exception occured so they can be safely registered again

  • django/contrib/admin/__init__.py

     
    1616        except ImportError:
    1717            # there is no app admin.py, skip it
    1818            continue
    19         __import__("%s.admin" % app)
     19        try:
     20            models_registered_before_import = site._registry.keys()
     21            __import__("%s.admin" % app)
     22        except:
     23            # Unregister the models that were registered in the last import as this import will have
     24            # to reoccur on the next request and this would raise AlreadyRegistered exceptions (see #8245).
     25            for model, admin_class in site._registry.items():
     26                if model not in models_registered_before_import:
     27                    site.unregister(model)
     28            raise
Back to Top